Advertisement
Garey

Danny Code

Mar 11th, 2018
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string danny_code(string);
  7.  
  8. int main() {
  9.  
  10.     string str;
  11.  
  12.     cout << "Enter sentence to encrypt: ";
  13.     getline(cin, str);
  14.  
  15.     string encrypted = danny_code(str);
  16.  
  17.     cout << "\n\nEncrypted: " << danny_code(str);
  18.     cout << "\n\nDecrypted: " << danny_code(encrypted);
  19.  
  20.     return 0;
  21. }
  22.  
  23. string danny_code(string str) {
  24.  
  25.     char key[5] = { 'D', 'A', 'N', 'N', 'Y' };
  26.  
  27.     string result = str;
  28.  
  29.     for (size_t i = 0; i < str.length(); i++)
  30.         result[i] = str[i] ^ key[i % (sizeof(key) / sizeof(char))];
  31.  
  32.     return result;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement