Beispiel #1
0
int main()
{
    const string plainText =
            "MOST GOOD PROGRAMMERS DO PROGRAMMING NOT BECAUSE "
            "THEY EXPECT TO GET PAID OR GET ADULATION BY THE PUBLIC "
            "BUT BECAUSE IT IS FUN TO PROGRAM"; // Quote by Linus Torvalds

    cout << "Plain message: " << endl
         << plainText << endl << endl;

    /*************************************************************************/

    const int privateKey = 5;

    cout << "Private key: " << endl
         << privateKey << endl << endl;

    string cipherText = CaesarCipher::encrypt(plainText, privateKey);
    cout << "Ciphered message: " << endl
         << cipherText << endl << endl;

    string decipheredText = CaesarCipher::decrypt(cipherText, privateKey);
    cout << "Deciphered message using known key: " << endl
         << decipheredText << endl << endl;

    /*************************************************************************/

    CaesarCipher mCipher;
    string autoDecryptedText = mCipher.decrypt(cipherText);

    cout << "Deciphered message using auto key finder: " << endl
         << autoDecryptedText << endl << endl;

    cout << "Possible key used: "
         << mCipher.getPossiblePrivateKey() << endl;

    return 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;
}