std::string
encrypt(
conststd::string &text,
const int&key) {
48std::string encrypted_text =
"";
49 for(
auto&c: text) {
50 charencrypted_char = char(c ^ key);
51encrypted_text += encrypted_char;
53 returnencrypted_text;
61std::string
decrypt(
conststd::string &text,
const int&key) {
62std::string decrypted_text =
"";
63 for(
auto&c : text) {
64 chardecrypted_char = char(c ^ key);
65decrypted_text += decrypted_char;
67 returndecrypted_text;
77std::string text1 =
"Whipalsh! : Do watch this movie...";
80assert(text1 == decrypted1);
81std::cout <<
"Original text : "<< text1;
82std::cout <<
" , Encrypted text (with key = 17) : "<< encrypted1;
83std::cout <<
" , Decrypted text : "<< decrypted1 << std::endl;
85std::string text2 =
"->Valar M0rghulis<-";
88assert(text2 == decrypted2);
89std::cout <<
"Original text : "<< text2;
90std::cout <<
" , Encrypted text (with key = 29) : "<< encrypted2;
91std::cout <<
" , Decrypted text : "<< decrypted2 << std::endl;
Functions for XOR cipher algorithm.
Algorithms for encryption and decryption.
std::string decrypt(const std::string &text, const int &key)
std::string encrypt(const std::string &text, const int &key)
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