#include <iostream>
#include <cstdlib>
#include <cstdio>
usingnamespace std;
/*
!!! source: http://www.cplusplus.com/articles/Ly86b7Xj/ !!!
*/
int main (int argc, char** argv){
string toEncrypt;
cin >> toEncrypt;
char keyToEncrypt = 's'; //remember 115 in ascii
for (int temp = 0; temp < toEncrypt.size(); temp++)
toEncrypt[temp] ^= keyToEncrypt;
cout << "\nThe encrypted data = " << toEncrypt;
for (int temp = 0; temp < toEncrypt.size(); temp++)
toEncrypt[temp] ^= keyToEncrypt; //notice we're using the exact same key, to unencrypt the data.
cout << "\nThe unencrypted data = " << toEncrypt;
cout << "\n";
return 0;
}
Works fine with single words, but as soon as you want to encrypt a sentence, it does not work :( (try a single word, then try "This is a test", which will only en- and decrypt This . Why? Can you please help me?