0% found this document useful (0 votes)
4 views

5th Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

5th Program

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

/*To encrypt a 64-bit plain text using DES algorithm*/

int s00[4][4]={{1,0,3,2},{3,2,1,0},{0,2,1,3},{3,1,3,2}},s0,s1;
int s11[4][4]={{0,1,2,3},{2,0,1,3},{3,0,1,0},{2,1,0,3}};
int f1[4],f2[4],k1[8]={1,0,1,0,0,1,0,0},k2[8]={0,1,0,0,0,0,1,1};
int ip[8],ipi[8]={1,5,2,0,3,7,4,6},cp[8],epi[8]={3,0,1,2,1,2,3,0},ep[8];
int p[4],r1,c1,r2,c2,p4[4],p44[4]={1,3,2,0},i,j,k[10],r[4],c=0,rs[8];
int p2[8]={1,0,0,0,1,1,0,1},ipii[8]={3,0,2,4,6,1,7,5},p1[8];
main()
{
clrscr();
printf("\n Enter the 8 bits of plain text:");
for(i=0;i<8;i++)
scanf("%d",&p1[i]);
printf("\n enter the 10-bit key:");
scanf("%d", &k[i]);
for(i=0;i<8;i++)
ip[i]=p1[ipi[i]];
fn();
c++;
fn();
for(i=0;i<4;i++)
ip[i]=r[i];
for(i=0,j=4;i<4;i++,j++)
ip[j]=f2[i];
for(i=0;i<8;i++)
cp[i]=ip[ipii[i]];
printf("\n The cipher text is \n");
for(i=0;i<8;i++)
printf("%d,\t",cp[i]);
return 0;
}

int fn()
{
for(i=0,j=0;i<4;i++,j++)
f1[j]=ip[i];
for(i=4,j=0;i<8;i++,j++)
f2[j]=ip[i];
for(i=0;i<8;i++)
ep[i]=f2[epi[i]];
if(c==0)
{
for(i=0;i<8;i++)
{
if(k1[i]==ep[i])
rs[i]=0;
else
rs[i]=1;
}
}
else
{
for(i=0;i<8;i++)
{
if(k2[i]==ep[i])
rs[i]=0;
else
rs[i]=1;
}
}
r1=rs[0]*2+rs[3]*1;
c1=rs[1]*2+rs[2]*1;
r2=rs[4]*2+rs[7]*1;
c2=rs[5]*2+rs[6]*1;
s0=s00[r1][c1];
s1=s11[r2][c2];
i=0;
p[i]=s0/2;i++;
p[i]=s0%2;i++;
p[i]=s1/2;i++;
p[i]=s1%2;

for(i=0;i<4;i++)
p4[i]=p[p44[i]];
for(i=0;i<4;i++)
{
if(p4[i]==f1[i])
r[i]=0;
else
r[i]=1;
}
for(i=0;i<4;i++)
ip[i]=f2[i];
for(i=0,j=4;i<4;i++,j++)
ip[j]=r[i];
return 0;
}

You might also like