get_char(
const intx) {
53 inline intget_value(
const charc) {
65std::string
encrypt(
conststd::string &text,
const int&shift) {
66std::string encrypted_text =
"";
67 for(
charc : text) {
68 intplace_value = get_value(c);
69place_value = (place_value + shift) % 26;
70 charnew_char = get_char(place_value);
71encrypted_text += new_char;
73 returnencrypted_text;
81std::string
decrypt(
conststd::string &text,
const int&shift) {
82std::string decrypted_text =
"";
83 for(
charc : text) {
84 intplace_value = get_value(c);
85place_value = (place_value - shift) % 26;
86 if(place_value < 0) {
87place_value = place_value + 26;
89 charnew_char = get_char(place_value);
90decrypted_text += new_char;
92 returndecrypted_text;
102std::string text1 =
"ALANTURING";
105assert(text1 == decrypted1);
106std::cout <<
"Original text : "<< text1;
107std::cout <<
" , Encrypted text (with shift = 21) : "<< encrypted1;
108std::cout <<
" , Decrypted text : "<< decrypted1 << std::endl;
110std::string text2 =
"HELLOWORLD";
113assert(text2 == decrypted2);
114std::cout <<
"Original text : "<< text2;
115std::cout <<
" , Encrypted text (with shift = 1729) : "<< encrypted2;
116std::cout <<
" , Decrypted text : "<< decrypted2 << std::endl;
std::string decrypt(const std::string &text, const int &shift)
std::string encrypt(const std::string &text, const int &shift)
Functions for Caesar cipher algorithm.
Algorithms for encryption and decryption.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4