Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- int main()
- {
- string plainAlphabet="abcdefghijklmnopqrstuvwxyz";
- string key;
- cout<<"the key is:"<<endl;
- cin>>key;
- string cipherAlphabet=key+plainAlphabet;
- string plainmsg;
- string ciphermsg;
- int changer;
- cout<<"Do you want to cipher or decipher?"<<endl;
- cin>>changer;
- cin.ignore();
- if(changer==1){
- cout<<"enter the plainmsg:"<<endl;
- getline(cin,plainmsg);
- for(int i=0;i<plainmsg.size();i++){
- for(int j=0;j<plainAlphabet.size();j++){
- if(plainmsg[i]==plainAlphabet[j]){
- plainmsg[i]=cipherAlphabet[j];
- break;
- }
- }
- }
- cout<<"ciphermsg is:"<<plainmsg<<endl;
- }
- else if(changer==2){
- cout<<"enter the ciphermsg"<<endl;
- getline(cin,ciphermsg);
- if(plainAlphabet.size()!=cipherAlphabet.size())
- return false;
- for(int y=0;y<ciphermsg.size();y++){
- for(int k=0;k<cipherAlphabet.size();k++){
- if(ciphermsg[y]==cipherAlphabet[k]){
- ciphermsg[y]=plainAlphabet[k];
- break;
- }
- }
- }
- cout<<"plainmsg is:"<<ciphermsg<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement