Advertisement
Guest User

Untitled

a guest
Aug 16th, 2020
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. using ll = long long;
  7.  
  8. void cypher(){
  9.     ll num,NUM;
  10.     cout << "Put a number, which you want to cypher: ";
  11.     cin >> num;
  12.     NUM = num;
  13.     string s_num;
  14.     while(num > 0){
  15.         ll k = num % 10;
  16.         s_num += (k + 7)%10 + '0';
  17.         num /= 10;
  18.     }
  19.     reverse(s_num.begin(),s_num.end());
  20.     swap(s_num[0],s_num[2]);
  21.     swap(s_num[1],s_num[3]);
  22.     cout << "Number before cyphering: " << NUM<< "\nNumber after cyphering: " << stoll(s_num);
  23. }
  24.  
  25. void decypher(){
  26.     ll num,NUM;
  27.     cout << "Put a number, which you want to cypher: ";
  28.     cin >> num;
  29.     NUM = num;
  30.     string s = to_string(num),ans,s_num;
  31.     while(s_num.length() + s.length() < 4)
  32.         s_num += '0';
  33.     s_num += s;
  34.     swap(s_num[0],s_num[2]);
  35.     swap(s_num[1],s_num[3]);
  36.     for(auto &i: s_num){
  37.         ll k = i - '0';
  38.         k - 7 >= 0 ? ans += (k-7) + '0' : ans += (k+3) + '0';
  39.     }
  40.     cout << "Number before decyphering: " << NUM << "\nNumber after decyphering: " << stoll(ans);
  41. }
  42.  
  43. int main() {
  44.     string choice;
  45.     cout << "What do you want to do with your number? Put CYPHER or DECYPHER\n";
  46.     cin >> choice;
  47.     while(choice != "CYPHER" && choice != "DECYPHER"){
  48.         cout << "Incorrect data. Try again. Put CYPHER ot DECYPHER\n";
  49.         cin >> choice;
  50.     }
  51.     choice == "CYPHER" ? cypher() : decypher();
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement