Write a program to implement RSA algorithm using C.
Program Code:
#include
#include
#include
#include
void main()
{
int p,q,n,e=1,j;
int d=1,i1;
int t1,t2,pt[10],ct[10],rt[10];
char i[10];
clrscr();
printf("\n\nEnter the two prime no. : ");
scanf("%d %d",&p,&q);
printf("\n\nEnter the message to be sent : ");
scanf("%s",i);
i1=strlen(i);
for(j=0;j
n=p*q;
t1=p-1;
t2=q-1;
while((t1*t2)%e==0)
e++;
for(j=0;j
printf("\nSender Side:");
printf("\n----------------");
printf("\nPublic Key(e)=%d",e);
for(j=0;j
//Receiver side
printf("\n\nReceiver Side:");
printf("\n-----------------");
while((d*e)%(t1*t2)!=1)
d++;
printf("\n\nPrivate key(d)=%d",d);
for(j=0;j
rt[j]=((int)pow(ct[j],d))%n;
printf("\n\nPlain Text=%d",rt[j]);
}
printf("\n\nDecrypted Message:");
for(j=0;j
rt[j]=rt[j]+96;
printf("%c",rt[j]);
}
getch();
}
Output:
Enter the two prime no. : 3
5
Enter the message to be sent : abcdef
Sender Side:
----------------
Public Key(e)=3
Cipher Text = 1
Cipher Text = 8
Cipher Text = 12
Cipher Text = 4
Cipher Text = 5
Cipher Text = 6
Receiver Side:
-----------------
Private key(d)=3
Plain Text=1
Plain Text=2
Plain Text=3
Plain Text=4
Plain Text=5
Plain Text=6
Decrypted Message: abcdef
Wednesday, January 7, 2009
Write a program to implement RSA algorithm using C.
Posted by ars at 9:02 PM
Subscribe to:
Post Comments (Atom)



0 comments:
Post a Comment