Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- using ll = long long;
- void cypher(){
- ll num,NUM;
- cout << "Put a number, which you want to cypher: ";
- cin >> num;
- NUM = num;
- string s_num;
- while(num > 0){
- ll k = num % 10;
- s_num += (k + 7)%10 + '0';
- num /= 10;
- }
- reverse(s_num.begin(),s_num.end());
- swap(s_num[0],s_num[2]);
- swap(s_num[1],s_num[3]);
- cout << "Number before cyphering: " << NUM<< "\nNumber after cyphering: " << stoll(s_num);
- }
- void decypher(){
- ll num,NUM;
- cout << "Put a number, which you want to cypher: ";
- cin >> num;
- NUM = num;
- string s = to_string(num),ans,s_num;
- while(s_num.length() + s.length() < 4)
- s_num += '0';
- s_num += s;
- swap(s_num[0],s_num[2]);
- swap(s_num[1],s_num[3]);
- for(auto &i: s_num){
- ll k = i - '0';
- k - 7 >= 0 ? ans += (k-7) + '0' : ans += (k+3) + '0';
- }
- cout << "Number before decyphering: " << NUM << "\nNumber after decyphering: " << stoll(ans);
- }
- int main() {
- string choice;
- cout << "What do you want to do with your number? Put CYPHER or DECYPHER\n";
- cin >> choice;
- while(choice != "CYPHER" && choice != "DECYPHER"){
- cout << "Incorrect data. Try again. Put CYPHER ot DECYPHER\n";
- cin >> choice;
- }
- choice == "CYPHER" ? cypher() : decypher();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement