Sunday, May 20, 2018

Multiplicative Cipher Encryption - Decryption Program

/* Program to implement Multiplicative Cipher encryption and decryption technique.
*/

#include<iostream>
#include<string.h>
using namespace std;
int inverse(int);
int main()
{
char str[100];
int key;
cout<<"\nEnter the string for encryption: ";
cin>>str;
cout<<"Enter the multiplicative cipher key: ";
cin>>key;
int h=strlen(str);
for(int i=0;i<h;i++)
{
char c=(((toascii(str[i])-97)*key)%26)+97;
cout<<str[i]<<"\t"<<((toascii(str[i])-97)*key)%26<<"\t"<<c<<endl;
}

char str1[100];
int key1;
cout<<"\nEnter the string for decryption: ";
cin>>str1;
cout<<"Enter the multiplicative decipher key: ";
cin>>key1;
int h1=strlen(str1);
int inv=inverse(key1);
for(int i=0;i<h1;i++)
{
int dkey=(((toascii(str1[i])-97)*inv))%26;
char ch=dkey+97;
cout<<str1[i]<<"\t"<<dkey<<"\t"<<ch<<"\n";
}
return 0;
}

int inverse(int key1)
{
int r1,r2,r,q,t1,t2,t;
r1=26; r2=key1;
t1=0; t2=1;
while(r2>0)
{
q=r1/r2;
r=r1-q*r2;
r1=r2; r2=r;
t=t1-q*t2;
t1=t2; t2=t;
}
if(r1==1)
{
if(t1<0)
t1+=26;
return t1;
}
}




OUTPUT SCREEN:



No comments:

Post a Comment

Project on Library Management System (C++)

=> The project titled Library Management system is Library management software for monitoring and controlling the transactions in a lib...