#include #include using namespace std; const string alpha = "abcdefghijklmnopqrstuvwxyz "; const string randa = "hurdmyboxkgavsejcpzwinltqf "; int position(char c, string s) { for (int i = 0; i < s.length(); i += 1) if (s[i] == c) return i; return -1; } char encrypt(char c) { int pos = position(c, alpha); if (pos == -1) return c; else return randa[pos]; } char decrypt(char c) { int pos = position(c, randa); if (pos == -1) return c; else return alpha[pos]; } void encrypt(string & word) { for (int i = 0; i < word.length(); i += 1) word[i] = encrypt(word[i]); } void decrypt(string & word) { for (int i = 0; i < word.length(); i += 1) word[i] = decrypt(word[i]); } int main() { while (true) { cout << "Type a word: "; string word; cin >> word; encrypt(word); cout << "Encrypted = " << word << "\n"; decrypt(word); cout << "re-decrypted = " << word << "\n"; } }