Program No 1: Implementation of Caeser Cipher Technique: Computer Network Lab (Eit-651) IT-2
Program No 1: Implementation of Caeser Cipher Technique: Computer Network Lab (Eit-651) IT-2
Program No 1: Implementation of Caeser Cipher Technique: Computer Network Lab (Eit-651) IT-2
IT-2
#include<stdio.h> #include<conio.h> #include<string.h> void main() { int shift,i; char message[81]; clrscr(); printf("Enter message to be encrypted: "); scanf("%s", &message); printf("Enter shift amount (1-25): "); fflush(stdin); scanf("%d", &shift); for(i=0;i<strlen(message);i++) { if((message[i]>='A')&& (message[i]<='Z')) message[i]=((message[i]-'A') + shift) % 26 + 'A'; else if((message[i]>='a')&& (message[i]<='z')) message[i]=((message[i]-'a') + shift) % 26 + 'a'; }
printf("\n\n%s",message); getch();}
Somya Arya 0909113114
IT-2
IT-2
PROGRAM NO 2: IMPLEMENTATION OF RAILFENCE CIPHER TECHNIQUE #include<conio.h> #include<stdio.h> void main(){ int i,j,k=0,l=0,m=0; char s[20],a[10],b[10]; clrscr(); printf("enter a string:"); scanf("%s",s); for(i=0;i<strlen(s);i++){ if(i%2==0){ a[k]=s[i]; k++;} else{ b[l]=s[i]; l++;}} for(i=0;i<k;i++){ printf("%c ",a[i]); s[m]=a[i]; m++;} printf("\n"); for(i=0;i<l;i++){ printf(" %c",b[i]); s[m]=b[i]; m++;} printf("\n\ncipher text is %s",s); getch();}
IT-2
IT-2
PROGRAM NO 3: IMPLEMENTATION OF RSA ALGORITHM. #include<stdio.h> #include<conio.h> #include<math.h> void main(){ int p,q,pl,n,phi,e,d,c,m,i=0,j,z=0,k,l,u=0,t=0; clrscr(); d=1; while(z==0){ t=0;u=0; printf("enter prime numbers p and q :"); scanf("%d%d",&p,&q); k=sqrt(p); l=sqrt(q); for(j=2;j<=k;j++){ if(p%j==0){ t++;}} for(j=2;j<=l;j++){ if(q%j==0){ u++;}} if(t==0&&u==0){ z++;} else{ printf("either p or q or both are not prime number :\n");}} n=p*q; phi=(p-1)*(q-1); printf("enter public key e :"); scanf("%d",&e);
Somya Arya 0909113114
IT-2
while(i==0){ if((d*e)%(phi)==1){ i++;} d++;} d=d-1; printf("the private key is %d",d) ; printf("enter plain text :"); scanf("%d",&m); c=pow(m,d); c=c%n; printf("the cipher text is %d",c); pl=pow(c,e); pl=pl%n; printf("the plain text is%d",pl); getch();}
OUTPUT : Output 1: enter prime numbers p and q 4 6 either p or q or both are not prime number : enter prime numbers p and q 6 8 either p or q or both are not prime number : enter prime numbers p and q 3
Somya Arya 0909113114
IT-2
5 enter public key e :3 the private key is 3 enter plain text :5 the cipher text is 5 the plain text is5
output 2: enter prime numbers p and q : 6 14 either p or q or both are not prime number : enter prime numbers p and q : 3 11 enter public key e :7 the private key is 3 enter plain text5 the cipher text is 26 the plain text is 5
IT-2
PROGRAM NO 4: IMPLEMENTATION OF DELPHI-HELLMAN ALGORITHM #include<stdio.h> #include<conio.h> #include<math.h> void main(){ int p,g,a,b,aa=1,bb=1,s1=1,s2=1,k,y,l,z,i=0,t=0,u=0; clrscr(); while(i==0){ t=0;u=0; printf("enter the global parameter p & g :"); scanf("%d%d",&p,&g); k=sqrt(p); l=sqrt(g); for(z=2;z<=k;z++){ if(p%z==0){ u++;}} for(z =2;z<=l;z++){ if(g%z==0){ t++;}} if(u==0&&t==0){ i++;} else{ printf("either p or g or both not prime :");}} printf("enter the value of key :"); scanf("%d%d",&a,&b); for(y=1;y<=a;y++){ aa=aa*(g%p);
Somya Arya 0909113114
IT-2
aa=aa%p;} printf("\t%d",aa); for(y=1;y<=b;y++){ bb=bb*(g%p); bb=bb%p;} printf("\t%d",bb); for(y=1;y<=a;y++){ s1=s1*(bb%p); s1=s1%p;} for(y=1;y<=b;y++){ s2=s2*(aa%p); s2=s2%p;} printf("shared key s1 and s2 are :%d\t%d ",s1,s2); getch();}
OUTPUT : OUTPUT 1: enter the global parameter p & g : 4 8 either p or g or both not prime :enter the global parameter p & g : 3 6 either p or g or both not prime :enter the global parameter p & g : 23 5 enter the value of key : 2
Somya Arya 0909113114
IT-2
OUTPUT 2: enter the global parameter p & g : 2 6 either p or g or both not prime :enter the global parameter p & g : 23 5 enter the value of key : 6 15 shared key s1 and s2 are: 2 2