//Program for Encryption and Decryption using structure.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct data
{
char alpha;
char code;
};
void main()
{
data b[]={{'A','à'},{'B','@'},{'C','Z'},{'D','W'},{'E','T'},{'F','Q'},{'G','N'},{'H','K'},{'I','H'},{'J','E'},{'K','B'},{'L','A'},{'M','C'},{'N','F'},{'O','I'},{'P','L'},{'Q','O'},{'R','R'},{'S','U'},{'T','X'},{'U','Y'},{'V','V'},{'W','S'},{'X','P'},{'Y','M'},{'Z','J'}};
char a[26],ch,c[26];
char E,D;
int i,j,k;
clrscr();
cout<<"Enter E for Encryption and D for decryption: ";
cin>>E;
if(E=='E')
{
cout<<"Enter a string: ";
i=0;
while((ch=getchar())!='\n')
{
a[i]=ch;
i++;
}
a[i]='\0';
for(i=0;a[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(a[i]==b[j].alpha)
{
c[i]=b[j].code;
break;
}
}
}
c[i]='\0';
cout<<c;
}
else if(E=='D')
{
cout<<"Enter a string: ";
i=0;
while((ch=getchar())!='\n')
{
a[i]=ch;
i++;
}
a[i]='\0';
for(i=0;a[i]!='\0';i++)
{
for(j=0;j<26;j++)
{
if(a[i]==b[j].code)
{
c[i]=b[j].alpha;
break;
}
}
}
c[i]='\0';
cout<<c;
}
else
{
cout<<"Invalid Input!!";
}
getch();
}