Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8. string alphabet {"[ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
  9. string key {" [XZNLWEBGJHQDYVTKFUOMPCIASRxznlwebgjhqdyvtkfuompciasr"};
  10.  
  11. string secret_message {};
  12. cout << "Enter your secret message : ";
  13. getline(cin, secret_message);
  14.  
  15. string encrypted_message {};
  16.  
  17. cout << "\nEncrypting message..." << endl;
  18.  
  19. for (char c: secret_message) {
  20. size_t position = alphabet.find(c);
  21. if (position != string::npos) {
  22. char new_char { key.at(position) };
  23. encrypted_message += new_char;
  24. } else {
  25. encrypted_message += c;
  26. }
  27. }
  28.  
  29. cout << "\nEncrypted message: " << encrypted_message << endl;
  30.  
  31. string decrypted_message {};
  32. cout << "\nDecrypting message..." << endl;
  33.  
  34. for (char c: encrypted_message) {
  35. size_t position = key.find(c);
  36. if (position != string::npos) {
  37. char new_char { alphabet.at(position) };
  38. decrypted_message += new_char;
  39. } else {
  40. decrypted_message += c;
  41. }
  42. }
  43.  
  44. cout << "\nDecrypted message: " << decrypted_message << endl;
  45.  
  46. cout << endl;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement