/* Program to implement Additive Cipher encryption and decryption technique.
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[100];
int key;
cout<<"\nEnter the message for encryption: ";
cin>>str;
cout<<"Enter the additive 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<<"\n";
}
char str1[100];
int key1;
cout<<"\nEnter the message for decryption: ";
cin>>str1;
cout<<"Enter the additive decipher key: ";
cin>>key1;
int h1=strlen(str1);
for(int i=0;i<h1;i++)
{
int dkey=((toascii(str1[i])-97)-key1)%26;
if(dkey<0)
dkey+=26;
char ch=dkey+97;
cout<<str1[i]<<"\t"<<dkey<<"\t"<<ch<<"\n";
}
cout<<"\n";
}
OUTPUT SCREEN:
*/
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char str[100];
int key;
cout<<"\nEnter the message for encryption: ";
cin>>str;
cout<<"Enter the additive 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<<"\n";
}
char str1[100];
int key1;
cout<<"\nEnter the message for decryption: ";
cin>>str1;
cout<<"Enter the additive decipher key: ";
cin>>key1;
int h1=strlen(str1);
for(int i=0;i<h1;i++)
{
int dkey=((toascii(str1[i])-97)-key1)%26;
if(dkey<0)
dkey+=26;
char ch=dkey+97;
cout<<str1[i]<<"\t"<<dkey<<"\t"<<ch<<"\n";
}
cout<<"\n";
}
OUTPUT SCREEN:
No comments:
Post a Comment