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; }
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; }
#define CATCH_CONFIG_MAIN #include "catch.hpp" #include "CaesarCipher.hpp" #include "ProcessCommandLine.hpp" CaesarCipher my_cipher = CaesarCipher("5"); TEST_CASE("Indices are properly wrapped","[wrapping]") { REQUIRE((my_cipher.wrapIt(27) == 1)); REQUIRE(( my_cipher.wrapIt(-3) == 23 )); } TEST_CASE("Characters are correctly shifted","[shift]") { REQUIRE(false); } TEST_CASE("Strings are correctly encrypted", "[encryption]") { }