Advertisement
AquaBlitz11

Caesar Decrypt

Oct 19th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. // string decrypt(string msg, int key)
  6. string decrypt(string msg)
  7. {
  8.     int key = 3;
  9.     for (int i = 0; i < msg.length(); i++)
  10.     {
  11.         if (isupper(msg[i]))
  12.             msg[i] = (msg[i] - 'A' - key) % 26 + 'A';
  13.         else if (islower(msg[i]))
  14.             msg[i] = (msg[i] - 'a' - key) % 26 + 'a';
  15.     }
  16.     return msg;
  17. }
  18.  
  19. int main()
  20. {
  21.     string message;
  22.     getline(cin, message);
  23.     cout << decrypt(message) << endl;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement