Ceaser cipher

mail@pastecode.io avatar
unknown
plain_text
2 years ago
830 B
0
Indexable
Never
#include<bits/stdc++.h>
using namespace std;

int main(){
    int t,n,i,j,k,sum=0;
    string m, key;
 
    cout<<"Enter the message: ";
    cin>>m;
    
    cout<<"Enter the key: ";
    cin>>key;
    
    int mod = key.size();
    j=0;
    
    for(i=key.size();i<m.size();i++){
        key+=key[j%mod];
        j++;
    }
    
    string ans="";
    
    for(i=0;i<m.size();i++){
    		
	    	if(islower(m[i]))
				ans += (m[i]-key[i]+26)%26+'a';
				
			else if (isupper(m[i]))
				ans += (m[i]-key[i]+26)%26+'A';	
			
			else
				cout << "Unsupported Character!";
			
    }
    cout<<"Encrypted message: "<<ans;
	
/*complete this code by adding below requirement:
- include uppercase letter
- must bu in range a-z
- do decryption as same as encryption requirement.*/
	
	return 0;
}