Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. using namespace std;
  2.  
  3.  
  4. int main()
  5. {
  6.     string plainAlphabet="abcdefghijklmnopqrstuvwxyz";
  7.     string key;
  8.     cout<<"the key is:"<<endl;
  9.     cin>>key;
  10.     string cipherAlphabet=key+plainAlphabet;
  11.     string plainmsg;
  12.     string ciphermsg;
  13.     int changer;
  14.     cout<<"Do you want to cipher or decipher?"<<endl;
  15.     cin>>changer;
  16.     cin.ignore();
  17.     if(changer==1){
  18.        cout<<"enter the plainmsg:"<<endl;
  19.        getline(cin,plainmsg);
  20.        for(int i=0;i<plainmsg.size();i++){
  21.             for(int j=0;j<plainAlphabet.size();j++){
  22.                     if(plainmsg[i]==plainAlphabet[j]){
  23.                             plainmsg[i]=cipherAlphabet[j];
  24.                             break;
  25.                     }
  26.             }
  27.        }
  28.        cout<<"ciphermsg is:"<<plainmsg<<endl;
  29.     }
  30.     else if(changer==2){
  31.          cout<<"enter the ciphermsg"<<endl;
  32.          getline(cin,ciphermsg);
  33.          if(plainAlphabet.size()!=cipherAlphabet.size())
  34.              return false;
  35.          for(int y=0;y<ciphermsg.size();y++){
  36.               for(int k=0;k<cipherAlphabet.size();k++){
  37.                      if(ciphermsg[y]==cipherAlphabet[k]){
  38.                             ciphermsg[y]=plainAlphabet[k];
  39.                              break;
  40.                      }
  41.               }
  42.          }
  43.          cout<<"plainmsg is:"<<ciphermsg<<endl;
  44.     }
  45.  
  46.    return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement