is print ready
TRANSCRIPT
-
7/28/2019 Is Print Ready
1/22
1 | 1 0 0 0 2 0 1 0 7 0 6 4
Sr. No. Practical Name Signature
1 Write a program to implement Ceaser cipher in C.
2 Write a program to implement monoalphabetic cipher in C.
3 Write a program to implement playfair cipher in C.
4 Write a program to implement Hill cipher in C.
5 Write a program to implement railfence cipher in C.
6 Write a program to implement columner cipher in C.
7 Write a program to implement RSA in C.
INTERNET SECURITY
>>INDEX
-
7/28/2019 Is Print Ready
2/22
2 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No. 1
AIM:- Write a program to implement Ceaser
cipher in C.
#include
#include
#include
void main()
{
int i,j,shift,k,temp;
char pt[100],ency[100];
char value(int); clrscr();
printf("Please Enter The PlainText=\n");
gets(pt);printf("Please Enter The shift value=\n");
scanf("%d",&shift);
printf("\n \n The Encrypted Text is=\n");
for (i=0;i
-
7/28/2019 Is Print Ready
3/22
3 | 1 0 0 0 2 0 1 0 7 0 6 4
else
{
if (ency[i]=='.')
{
printf("%c",pt[i]);
}else
{
temp=ency[i]-shift;
printf("%c",temp);
}
}
}
ency[i]='\0';
getch();
}
-
7/28/2019 Is Print Ready
4/22
4 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Pleas Enter the Planitext=
Milan
Pleas Enter The Shift Value=
2
The Encrypted text is=
Oknco
The Decrypted Text is=
milan
-
7/28/2019 Is Print Ready
5/22
5 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No. 2
AIM:-Write a program to implement MONOALPHABETIC cipher in C.
#include
#include#include
void main()
{
int i,length,temp;
char a[100],encrypt[100],decrypt[100];
char cipher(char,int);
clrscr();
printf("Enter The PlainText=\n");
gets(a);length=strlen(a);
temp=0;
printf("The Encrypted Message=\n");
for (i=0;i
-
7/28/2019 Is Print Ready
6/22
6 | 1 0 0 0 2 0 1 0 7 0 6 4
case 'd':
return ('e');
case 'e':
return ('f');
case 'f':
return ('g');
case 'g':
return ('h');
case 'h':
return ('i');
case 'i':
return ('j');
case 'j':
return ('k');
case 'k':
return ('l');
case 'l':
return('m');case 'm':
return ('n');
case 'n':
return ('o');
case 'o':
return ('p');
case 'p':
return ('q');
case 'q':
return ('r');
case 'r':return ('s');
case 's':
return ('t');
case 't':
return ('u');
case 'u':
return ('v');
case 'v':
return (w');
case 'w':
return ('x');case 'x':
return ('y');
case 'y':
return ('z');
case 'z':
return ('a');
}
}}
else{return(' '); }
}
}
-
7/28/2019 Is Print Ready
7/22
7 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Enter The Plaintext=
Milan
The Encrypted Message=
njmbo
The Decrypted Message=
milan
-
7/28/2019 Is Print Ready
8/22
8 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No. 3
AIM:-Write a program to implement Playfair cipher in C.
#include
#include
#include
void main()
{
char key[10],a[5][5],pt[100],ct[100];
int row=0,col=0,x,y,i,j,flag=0;
clrscr();
printf(" enter key\n ");
gets(key);
for(i=0;i
-
7/28/2019 Is Print Ready
9/22
9 | 1 0 0 0 2 0 1 0 7 0 6 4
if(key[j]==i+97)
{
flag=0;
}
}
if(flag==1 && i!=9)
{
a[row][col]=i+97;
printf(" %c",a[row][col]); col++;
if(col==5)
{
row=row+1;
col=0;
printf("\n");
}
}
}
printf("\n ");
printf("enter the plaintext:"); gets(pt);
j=1;
for(i=0;i
-
7/28/2019 Is Print Ready
10/22
10 | 1 0 0 0 2 0 1 0 7 0 6 4
{
r1=p;
c1=q;
}
if(a[p][q]==y)
{
r2=p;
c2=q;
}
}
}
if(r1==r2)
{
ct[i]=a[r1][(c1+1)%5]; ct[j]=a[r2][(c2+1)%5];
printf("%c%c",ct[i],ct[j]);
}
else if(c1==c2)
{
ct[i]=a[(r1+1)%5][c1];
ct[j]=a[(r2+1)%5][c2];
printf("%c%c",ct[i],ct[j]);
}
else
{
ct[i]=a[r1][c2];
ct[j]=a[r2][c1];
printf("%c%c",ct[i],ct[j]);
}
i+=2;
j+=2;
}
getch();
}
-
7/28/2019 Is Print Ready
11/22
11 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Enter Key:
Monkey
M o n k e
y a b c d
f g h i/j l
p q r s t
u v w x z
Enter The Plaintext : Milan
kfgd
-
7/28/2019 Is Print Ready
12/22
12 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No.4
AIM:-Write a program to implement HILL CIPHER in C.
#include
#include void main()
{
chars[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};char p[100],ency[100],decy[100];
int
i,j,a[10][10]={{6,24,1},{13,16,10},{20,17,15}},length,num[100],c[100],b[10][10]={{8,5,10},{21,8,21},{21,12,8}}; clrscr();
printf(" The Key is=\n"); for (i=0;i
-
7/28/2019 Is Print Ready
13/22
13 | 1 0 0 0 2 0 1 0 7 0 6 4
26]; ency[i]='\0';
puts(ency);
printf(" The Inverse Key
is=\n "); for (i=0;i
-
7/28/2019 Is Print Ready
14/22
14 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
The Key is=
6 24 1
13 16 10
20 17 17
Enter The Plaintext=
Milan
The encrypted Message is=
Vep
The Inverse Key is=
8 5 10
21 8 21
21 12 8
The Decrypted Message is=
milan
-
7/28/2019 Is Print Ready
15/22
15 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No.5
AIM:-Write a program to implement RAILFENCE cipher in C.
#include
#include
#include
void main()
{
int i,length,j,k,l,len1,len2,temp1,temp2,q;
char a[100],text1[100],text2[100],
encrypt[100],decrypttext1[100],decrypttext2[100],decrypt[100]
clrscr();
printf("Enter The PlainText=\n");
gets(a);
length=strlen(a); j=0;
k=0;
for (i=0;i
-
7/28/2019 Is Print Ready
16/22
16 | 1 0 0 0 2 0 1 0 7 0 6 4
len1=i;
for (l=0;l
-
7/28/2019 Is Print Ready
17/22
17 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Enter the plaintext=
Milan
The encrypted message is=
Mlnia
Decrypted message is=
milan
-
7/28/2019 Is Print Ready
18/22
18 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No.6
AIM:-Write a program to implement COLUMNER cipher in C.
#include
#include
#include
void main()
{
char a[100],b[100][100]={' '},ency[100]={' '},decy[100][100]={' '},temp[100][100]={' '};
int pattern[10]={7,0,9,5,1,6,3,4,2,8};
int length,i,j,k,l,m,condi,distance,p,length12,l1,l2;
clrscr();
printf("Enter The Message=\n");
gets(a);length=strlen(a); condi=length;
k=0;
l1=0;
l2=0;
printf("The Encryption Message is=\n");
if (length%10==0)
{
for (i=0;i
-
7/28/2019 Is Print Ready
19/22
19 | 1 0 0 0 2 0 1 0 7 0 6 4
distance=distance+length;
for (i=length;i
-
7/28/2019 Is Print Ready
20/22
20 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Enter the message=
Milan
The encryption message is=Xmxxixanlx
The decryption message is=
milan
-
7/28/2019 Is Print Ready
21/22
21 | 1 0 0 0 2 0 1 0 7 0 6 4
Practical No.7
AIM:-Write a program to implement RSA in C.
#include
#include
void main()
{
int p,q,n,e,i;
int temp,temp1,d,pt,c,m;
clrscr();
printf("Enter The first Prime number=\n"); scanf("%d",&p);
printf("Enter The second Prime number=\n"); scanf("%d",&q);
n=p*q; q=(p-1)*(q-1); e=2;
while (e>1)
{
if (q%e!=0)
goto end;
else
e++;
}
end :
d=1;
temp=e-2;d=((temp*q)+1)/e;
last:
printf("\n%d",d);
printf("\nThe Public Key is e={%d} and n={%d}\n",e,n);
printf("The Private Key is d={%d} and n={%d}\n",d,n);
printf("Enter The Plain Text=\n");
scanf("%d",&pt);
c=1;
printf("The cipher text is=\n");
for (i=0;i
-
7/28/2019 Is Print Ready
22/22
22 | 1 0 0 0 2 0 1 0 7 0 6 4
Output:
Enter the first prime number=
13
Enter the second prime number=
17
115
The public key is e={5} and n={221}
The private key is d={115} and n={221}
Enter the plain text=
Milan
The cipher text is=
138
The decrypted text is=
115