PlayFair Cipher Code by Khawar:
#include <iostream>
usingnamespace std;
intmain()
{
inti,j,x,r,n,z,c1,c2,p;c1=0;
char a2[25]={'a','b','c','d','e','f','g','h','i','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char key[50],aa[100];
cout<<"write yourcyphertextheren";
cin.getline(aa,100);
cout<<"enteryourkeyheren";
cin.getline(key,50);
intll=strlen(key);
char a[5][5];
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
c2=0;
if(c1<ll)
{
for(p=0;p<25;p++)
{
if(key[c1]==a2[p])
{
a[i][j]=key[c1];
c1++;c2=1; a2[p]='1';break;
}
if(p==24&&c2!=1)
{
p=0;c1++;
}
}
}
else
{
for(p=0;p<25;p++)
{
if(a2[p]!='1')
{
a[i][j]=a2[p];a2[p]='1';break;
}
}
}
}
}
cout<<"n";
intl=strlen(aa);
intro1,co1,ro2,co2;
x=0;
while(x<l)
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(aa[x]==a[i][j]){ro1=i;co1=j;}
if(aa[x+1]==a[i][j]){ro2=i;co2=j;}
}
}
if(ro1==ro2)
{
if(co1>0)
{
aa[x]=a[ro1][co1-1];
}
if(co2>0)
{
aa[x+1]=a[ro2][co2-1];
}
if(co1==0)
{
aa[x]=a[ro1][4];
}
if(co2==0)
{
aa[x+1]=a[ro2][4];
}
}
else if(co1==co2)
{
if(ro1>0)
{
aa[x]=a[ro1-1][co1];
}
if(ro2>0)
{
aa[x+1]=a[ro2-1][co2];
}
if(ro1==0)
{
aa[x]=a[4][co1];
}
if(ro2==0)
{
aa[x+1]=a[4][co2];
}
}
else
{
aa[x]=a[ro1][co2];
aa[x+1]=a[ro2][co1];
}
x=x+2;
}
cout<<"plantextis= "<<aa<<"n";
}
Thanks: