Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. string shifr(string a, int key)
  8. {
  9.     for (int i = 0; i < a.length(); i++)
  10.     {
  11.         if ((a[i] >= 'A' && a[i] <= 'Z'))
  12.         {
  13.             a[i] = (a[i] - 'A' + key) % 26 + 'A' ;
  14.         }
  15.  
  16.         if ((a[i] >= 'a' && a[i] <= 'z'))
  17.         {
  18.             a[i] = (a[i] - 'a' + key) % 26 + 'a';
  19.         }
  20.         if ((a[i] >= '0' && a[i] <= '9'))
  21.         {
  22.             a[i] = (a[i] - '0' + key) % 10 + '0';
  23.         }
  24.     }
  25.     return a;
  26. }
  27.  
  28. int main()
  29. {
  30.     string str; int k;
  31.     cout << "Enter string - "; getline(cin, str);
  32.     cout << "\nEnter key - "; cin >> k;
  33.    
  34.     str = shifr(str, k);
  35.     cout << '\n' << str;
  36.  
  37.     system("pause");
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement