Advertisement
makispaiktis

Atbas Encryption

Apr 13th, 2019 (edited)
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9. // Helpful Functions
  10. void displayVector(vector <char> v){
  11.     for(unsigned int i=0; i<v.size(); i++){
  12.         cout << v[i] << endl;
  13.     }
  14. }
  15.  
  16.  
  17. void displayMap(map <char,char> myMap){
  18.     map <char,char> :: iterator mitr;
  19.     for(mitr=myMap.begin(); mitr!=myMap.end(); mitr++){
  20.         cout << "Key: " << mitr->first << "    Value: " << mitr->second << endl;
  21.     }
  22. }
  23.  
  24. int main()
  25. {
  26.     // 1. Intro
  27.     cout << "This programme is about the famous code 'Atbas'.\n";
  28.  
  29.     //2. Create the vectors that contains all the letters of Alphabets
  30.     vector <char> alphabet = vector <char> ();
  31.     vector <char> alphabetReversed = vector <char> ();
  32.     for(char c='a'; c<='z'; c++){
  33.         alphabet.push_back(c);
  34.     }
  35.  
  36.     // 3. Create the 2'Atbas' maps: first for ciphering and the other one for deciphering
  37.     // Encryption
  38.     map <char,char> atbasEncryption = map <char,char> ();
  39.     map <char,char> atbasDecryption = map <char,char> ();
  40.  
  41.     for(unsigned int i=0; i<alphabet.size(); i++){
  42.         atbasEncryption.insert({alphabet[i],alphabet[alphabet.size()-1-i]});
  43.     }
  44.  
  45.     cout << "Write the message you want me to cipher:\n";
  46.     string message;
  47.     getline(cin, message);
  48.     string answer;
  49.  
  50.     if(message.size() == 0){
  51.         cout << "With 0 letters, what do you expect from me to do?" << endl << endl;
  52.         return 0;
  53.     }
  54.     else{
  55.         for(unsigned int i=0; i<message.size(); i++){
  56.             if(message[i] == ' '){
  57.                 answer += ' ';
  58.             }
  59.             else{
  60.                 answer += (atbasEncryption.find(message[i])->second);
  61.             }
  62.         }
  63.         cout << "Message before:    " << message << endl;
  64.         cout << "Message encrypted: " << answer << endl;
  65.     }
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement