#include <iostream>
#include "teconnection.h"
#include "teagent.h"
#include "teexception.h"
using namespace ERUCES;
using namespace std;
int main()
{
string strServerName = "localhost";
long lPort = 8888;
string strUsername = "alice";
string strPassword = "alice1A";
try
{
auto_ptr<TEConnection> conn =
TEConnection::createInstance(TEConnection::SecureConnection);
conn->open(strServerName, lPort, strUsername, strPassword);
cout << "Connected to " << strServerName << " at " << lPort
<< " as " << strUsername << "\n" << endl;
TEAgentMatrix matrix;
string str1_1 = "test string (1, 1)";
string str1_2 = "test string (1, 2)";
string str2_1 = "test string (2, 1)";
string str2_2 = "test string (2, 2)";
string str2_3 = "test string (2, 3)";
string str3_1 = "test string (3, 1)";
matrix.setElement(1, 1, str1_1);
matrix.setElement(1, 2, str1_2);
matrix.setElement(2, 1, str2_1);
matrix.setElement(2, 2, str2_2);
matrix.setElement(2, 3, str2_3);
matrix.setElement(3, 1, str3_1);
cout << "Before encryption:\n";
cout << "Original data:\n";
cout << str1_1 << ", " << str1_2 << endl;
cout << str2_1 << ", " << str2_2 << ", " << str2_3 << endl;
cout << str3_1 << endl;
matrix.attachConnection(conn.operator->());
matrix.encrypt();
matrix.detachConnection();
matrix.setEncodeMode(true);
string strHL1, strHL2, strHL3;
matrix.getHiddenLink(1, strHL1);
matrix.getHiddenLink(2, strHL2);
matrix.getHiddenLink(3, strHL3);
matrix.getElement(1, 1, str1_1);
matrix.getElement(1, 2, str1_2);
matrix.getElement(2, 1, str2_1);
matrix.getElement(2, 2, str2_2);
matrix.getElement(2, 3, str2_3);
matrix.getElement(3, 1, str3_1);
cout << "\nAfter encryption:\n";
cout << "HiddenLink:\n";
cout << strHL1 << "\n";
cout << strHL2 << "\n";
cout << strHL3 << "\n";
cout << "Encrypted data:\n";
cout << str1_1 << ", " << str1_2 << endl;
cout << str2_1 << ", " << str2_2 << ", " << str2_3 << endl;
cout << str3_1 << endl;
matrix.clear();
matrix.setDecodeMode(true);
matrix.setHiddenLink(1, strHL1);
matrix.setHiddenLink(2, strHL2);
matrix.setHiddenLink(3, strHL3);
matrix.setElement(1, 1, str1_1);
matrix.setElement(1, 2, str1_2);
matrix.setElement(2, 1, str2_1);
matrix.setElement(2, 2, str2_2);
matrix.setElement(2, 3, str2_3);
matrix.setElement(3, 1, str3_1);
matrix.attachConnection(conn.operator->());
matrix.decrypt();
matrix.detachConnection();
matrix.setEncodeMode(false);
matrix.getElement(1, 1, str1_1);
matrix.getElement(1, 2, str1_2);
matrix.getElement(2, 1, str2_1);
matrix.getElement(2, 2, str2_2);
matrix.getElement(2, 3, str2_3);
matrix.getElement(3, 1, str3_1);
cout << "\nAfter decryption:\n";
cout << "Decrypted data:\n";
cout << str1_1 << ", " << str1_2 << endl;
cout << str2_1 << ", " << str2_2 << ", " << str2_3 << endl;
cout << str3_1 << endl;
conn->close();
cout << "Disconnected from server." << endl;
}
catch (TEException &e)
{
cout << e.getAllMessages() << endl;
}
catch (...)
{
cout << "Unexpected error" << endl;
}
return 0;
}