Professional Documents
Culture Documents
Result:
Thus affine cipher algorithm is implemented successfully.
Output:
Result:
Thus hill cipher algorithm is implemented successfully.
Output:
Result:
Thus addition modulo of 8 and multiplicative modulo of 8 is executed successfully.
Output:
Result:
Thus playfair algorithm is executed successfully.
Output:
Result:
Thus a program is written successfully to find whether the given number is a prime and
its co-primes are printed.
Source Code:
#include<stdio.h>
int l[4],r[4],keys[2][8],ct[8];
void sbox(int sip[],int p[],int sbno,int i)
{
int sbox[2][4][4]={1,0,3,2,3,2,1,0,0,2,1,3,3,1,3,2,0,1,2,3,2,0,1,3,3,0,1,0,2,1,0,3};
int rw,c,sop;
rw = sip[3]+sip[0]*2;
c = sip[2]+sip[1]*2;
sop = sbox[sbno][rw][c];
//sop gives decimal value of S-Box Output
for(;sop!=0;sop/=2) p[i--]=sop%2;
}
void cmp_fun(int round)
{
int EP[]={4,1,2,3,2,3,4,1},i,epd[8];
int slip[4],srip[4];
int p[4]={0},p4[]={2,4,3,1},np[4];
for(i=0;i<8;i++) // E/P Permutation
epd[i]=r[EP[i]-1];
for(i=0;i<8;i++)//Performing XOR with Key
if(i<4) slip[i] = epd[i]^keys[round][i]; // Using Key _ 1=>0
else srip[i-4] = epd[i]^keys[round][i];
sbox(slip,p,0,1);//Calling SBox 1, 0->SBOX 1
sbox(srip,p,1,3);//Calling SBox 1, 1->SBOX 2
r[i]=l[i]+r[i],l[i]=r[i]-l[i],r[i]=r[i]-l[i];
printf("\n\n"); cmp_fun(!c); // Round 1+1 wid key1+1 wid swapped bits
for(i=0;i<8;i++)
if(i<4)
t[i]=l[i];
else t[i]=r[i-4];
for(i=0;i<8;i++) ct[i] = t[ipi[i]-1];
}
int main()
{
int pt[8]={0},i;
printf("\nSIMPLIFIED DES");
printf("\n--------------");
printf("\nEnter plain text in binary bits:");
for(i=0;i<8;i++)
scanf("%d",&pt[i]);
printf("\nSUBKEY GENERATION\n");
printf("\n-----------------");
gen_keys(); // Generating Keys key1 & key2
En_De(pt,0);
printf("\nENCRYPTION");
printf("\n----------");
printf("\nCipher Text:");
for(i=0;i<8;i++)
printf("%d",ct[i]);
//Decrypting - - En_De(ct,1);
printf("\nDECRYPTION");
printf("\n----------");
printf("\nPlain Text:");
for(i=0;i<8;i++)
printf("%d",ct[i]);
}
Output:
Result:
Thus a program is written successfully to encrypt and decrypt the given text using
simplified DES algorithm.