Professional Documents
Culture Documents
Practical: -9
#include<stdio.h>
#include<process.h>
#include<math.h>
void encrypt();
void decrypt();
printf("\nEncryption key(e,n):%ld\t%ld\n",e,n);
printf("\nDecryption key(d,n):%ld\t%ld\n",d,n);
void encrypt(){
scanf("%d",&pt);
scanf("%ld %ld",&p,&q);
n=p*q;
170160116109 IT-B2
Information and Network Security (2170709)
fn=(p-1)*(q-1);
temp=findGCD(e,fn);
while(temp!=1) {
e++;
temp=findGCD(e,fn);
d=multipicative_inverse(fn,e);
if(d==0) {
exit(0);
ct=fmod(pow(pt,e),n);
key_pair(e,n,d);
printf("\nencrypted text:\t%ld\n",ct);
void decrypt(){
scanf("%ld",&ct);
170160116109 IT-B2
Information and Network Security (2170709)
scanf("%ld %ld",&d,&n);
pt=fmod(pow(ct,d),n);
printf("Decrypted message:\t%ld",pt);
top:
if(b3==0) return 0;
else if(b3==1) {
q=a3/b3;
t1=b1;
t2=b2;
t3=b3;
b1=a1-(q*b1);
b2=a2-(q*b2);
b3=a3-(q*b3);
170160116109 IT-B2
Information and Network Security (2170709)
a1=t1;
a2=t2;
a3=t3;
goto top;
long int r;
while(d!=0) {
r=c%d;
c=d;
d=r;
return c;
int main(){
int choice;
while(1)
scanf("%d",&choice);
switch(choice) {
case 1: {
encrypt();
break;
case 2: {
decrypt();
break;
case 3: {
break;
default: {
if(choice==3)
break;
}
170160116109 IT-B2
Information and Network Security (2170709)
return 0;
Output: -
170160116109 IT-B2