Wednesday, January 2, 2013
RSA algorithm implementation C program
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
int p,q;
printf("Enter two prime numbers");
cin>>p>>q;
int n;
n=p*q;
cout<<"N:pq"<<n<<endl;
int z;
z=(p-1)*(q-1);
cout<<"Z:(p-1)(q-1)"<<z<<endl;
cout<<"Enter prime number k:";
int e;
cin>>e;
cout<<"Public key (n,e): ("<<n<<","<<e<<")"<<endl;
int d;
int i=1;
while(((z*i)+1)%e!=0)
{
i++;
cout<<"d"<<(z*i)+1<<endl;
}
d=((z*i)+1)/e;
cout<<"Public key (n,d): ("<<n<<","<<d<<")"<<endl;
int m;
cout<<"Enter plain text value in number :";
cin>>m;
int c=fmod(pow(m,e),n);
cout<<"Encrypted Cypher text value will be:"<<c<<endl;
m=fmod(pow(c,d),n);
cout<<"Decrypted Plane Text value will be:"<<m<<endl;
getch();
}
Values Are:
p=11
q=3
e=7
m=2
No comments:
Post a Comment