Here's some code for cin that encrypts with 3. You probably want the key to be set once and used for every character instead of a different key for each character. That way you don't have to keep save all the keys for decryption.
To decrypt you need the same key and just do -= instead of +=.Code:#include <iostream> #include <cctype> using namespace std; int main() { int key = 3; char x; while ( cin.get( x ) ) { if ( isalnum( x ) ) { x += key; } cout << x; } }