Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- using namespace std;
- int main()
- {
- string plaintext,encrypt,decrypt;
- int inv;
- cout<<"Enter the message to be encrypted:"<<endl;
- getline(cin,plaintext);
- float a,b;
- cout<<"Enter the values for a and b:"<<endl;
- cin>>a>>b;
- int length=(int)plaintext.length();
- for(int i=0;i<length;i++)
- {
- encrypt[i]=(char)(fmod((a*(plaintext[i]-97)+b),26)+97);
- }
- for(int i=0;i<length;i++)
- {
- if(encrypt[i]=='V')
- {
- cout<<" ";
- }
- else
- {
- cout<<encrypt[i];
- }
- }
- cout<<"\n";
- cout<<"The deciphered text is:"<<endl;
- int f=0;
- inv=0;
- for(int i=0;i<26;i++)
- {
- f=fmod((a*i),26);
- if(f==1)
- {
- inv=i;
- }
- }
- for(int i=0;i<length;i++)
- {
- decrypt[i]=(char)(fmod(inv*((encrypt[i]-97)-b),26)+97);
- }
- for(int i=0;i<length;i++)
- {
- if(decrypt[i]=='T')
- {
- cout<<" ";
- }
- else
- {
- cout<<decrypt[i];
- }
- }
- }
Add Comment
Please, Sign In to add comment