You can also Download the Program code and corresponding output....
To Download the program in correct format
CLICK HERE
#include
#include
int phi,m,n,e,d,c,flag;
int check()
{
int i;
for(i=3;e%i==0&φ%i==0;i+2)
{
flag=1;
return;
}
flag=0;
}
int encrypt()
{
int i;
c=1;
for(i=0;i
c=c*m%n;
c=c%n;
printf("\n\t Encrypted keyword is %d",c);
return c;
}
void decrypt()
{
int i;
m=1;
for(i=0;i
m=m*c%n;
m=m%n;
printf("\n\t decrypted keyword is %d",m);
}
void main()
{
int p,q,s;
clrscr();
printf("enter two relatively prime numbers");
scanf("%d%d",&p,&q);
n=p*q;
phi=(p-1)*(q-1);
printf("\n\t f(n)\t=%d",phi);
do
{
printf("\n\n Enter e\t");
scanf("%d",&e);
check();
}while(flag==1);
d=1;
do
{
s=(d*e)%phi;
d++;
}while(s!=1);
d=d-1;
printf("\n\t Public key{ %d,%d}",e,n);
printf("\n\t Private key{%d,%d}",d,n);
printf("\n\n Enter the plain text\t");
scanf("%d",&m);
encrypt();
decrypt(c);
getch();
}
OUTPUT
0 comments:
Post a Comment