示例#1
0
void testFactory(vector<char> data, seconds duration, seconds maxTimeToTest, int id)
{
	Puzzle p;
	HardwareSpeedTester hst(1000, maxTimeToTest);
	TimeCapsuleFactory<char> tcf(hst);
	//char rawdata[] = "Hey, I hope it will finish in time.. tho probably not :D ...";
	auto capsule = tcf.createTimeCapsule(p, data, duration);
	capsule.save("capsule_" + to_string(id) + ".dat");

	Capsule<char> capsule2;
	capsule2.load("capsule_" + to_string(id) + ".dat");

	auto crdata = capsule.getCryptedData();
	auto crdata2 = capsule2.getCryptedData();

	assert(capsule.getBase() == capsule2.getBase());
	assert(capsule.getN() == capsule2.getN());
	assert(capsule.getIV() == capsule2.getIV());
	assert(capsule.getCryptedKey() == capsule2.getCryptedKey());
	assert(capsule.getNumberOfOperations() == capsule2.getNumberOfOperations());
	Logger::log("Original crypted data size: " + to_string(crdata.size()));
	Logger::log("Copypasted crypted data size: " + to_string(crdata2.size()));

	string datastr(crdata.begin(), crdata.end());
	string datastr2(crdata2.begin(), crdata2.end());
	Logger::log("Original   crypted data: " + datastr);
	Logger::log("Copypasted crypted data: " + datastr2);

	//cout << capsule.getCryptedData().size() << ", " << capsule2.getCryptedData().size() << endl;
	//assert(capsule.getCryptedData().size() == capsule2.getCryptedData().size());
	//for (size_t i = 0; i < capsule.getCryptedData().size(); ++i)
	//	assert(capsule.getCryptedData()[i] == capsule2.getCryptedData()[i]);

	Puzzle p2(capsule2.getBase());

	auto start = chrono::high_resolution_clock::now();
	auto key = p2.solve(capsule2.getCryptedKey(), capsule2.getNumberOfOperations(), capsule2.getN());
	auto end = chrono::high_resolution_clock::now();

	Logger::log("Time specified to decode: " + to_string(duration.count()) + " seconds");
	Logger::log("Time taken to decode: " + to_string(chrono::duration_cast<seconds>(end - start).count()) + " seconds");
	
	Encryptor<char> cr;
	auto databack = cr.decrypt(capsule2.getCryptedData(), key, capsule2.getIV());
	string tmpdata(data.begin(), data.end());
	string tmpdataback(databack.begin(), databack.end());
	Logger::log("Original  data: " + tmpdata);
	Logger::log("Data decrypted: " + tmpdataback);

	/*char dummychar;
	if (crdata.size() != crdata2.size())
	{
		Logger::log("PARA VAN!");
		cin >> dummychar;
	}*/
}
示例#2
0
void testEncryptor()
{
	char plainText[] = "Hello! How are you.";
	vector<char> data(plainText, plainText + 20);
	Encryptor<char> enc;
	SecByteBlock key;
	SecByteBlock iv;

	auto cdata = enc.encrypt(data, key, iv);
	auto databack = enc.decrypt(cdata, key, iv);
	assert(data == databack);

	cout << cdata.data() << endl;
	cout << databack.data() << endl;
}