Esempio n. 1
0
CaesarCipher operator*(const CaesarCipher &c1, const CaesarCipher &c2)
{
	assert(((c2.key != 0 && c2.ciphertext.compare("") == 0 && c2.plaintext.compare("") == 0) || (c1.ciphertext.compare(c2.plaintext) == 0)) && "Cipher composition failed, text doesn't match.");
	CaesarCipher result;

	result.init(c1.plaintext, c2.ciphertext, ((c1.key + c2.key) % 26));
	if (c2.ciphertext.compare("") == 0)
			result.encrypt();
	return result;
}
Esempio n. 2
0
int main(int argc, const char *argv[]) {

	IOUtils io;
	io.openStream(argc,argv);
	std::string input, encrypted, decrypted;
	input = io.readFromStream();
	std::cout << "Original text:" << std::endl << input;

	CaesarCipher caesar;
	encrypted = caesar.encrypt(input);
	std::cout << "Encrypted text:" << std::endl << encrypted;

	decrypted = caesar.decrypt(encrypted);
	std::cout << "Decrypted text:" << std::endl << decrypted;

	if (decrypted == input) std::cout << "Decrypted text matches input!" << std::endl;
	else {
		std::cout << "Oops! Decrypted text doesn't match input!" << std::endl;
		return 1; 
	}

	return 0;
}