65 std::string encrypt (
const std::string &text,
const int &shift) {
66 std::string encrypted_text =
"";
68 int place_value = get_value(c);
69 place_value = (place_value + shift) % 26;
70 char new_char = get_char(place_value);
71 encrypted_text += new_char;
73 return encrypted_text;
81 std::string decrypt (
const std::string &text,
const int &shift) {
82 std::string decrypted_text =
"";
84 int place_value = get_value(c);
85 place_value = (place_value - shift) % 26;
87 place_value = place_value + 26;
89 char new_char = get_char(place_value);
90 decrypted_text += new_char;
92 return decrypted_text;
102 std::string text1 =
"ALANTURING";
103 std::string encrypted1 = ciphers::caesar::encrypt(text1, 17);
104 std::string decrypted1 = ciphers::caesar::decrypt(encrypted1, 17);
105 assert(text1 == decrypted1);
106 std::cout <<
"Original text : " << text1;
107 std::cout <<
" , Encrypted text (with shift = 21) : " << encrypted1;
108 std::cout <<
" , Decrypted text : "<< decrypted1 << std::endl;
110 std::string text2 =
"HELLOWORLD";
111 std::string encrypted2 = ciphers::caesar::encrypt(text2, 1729);
112 std::string decrypted2 = ciphers::caesar::decrypt(encrypted2, 1729);
113 assert(text2 == decrypted2);
114 std::cout <<
"Original text : " << text2;
115 std::cout <<
" , Encrypted text (with shift = 1729) : " << encrypted2;
116 std::cout <<
" , Decrypted text : "<< decrypted2 << std::endl;