Saturday, May 8, 2010

NIS RSA Algorithm

#include
#include
#include

void main()
{
clrscr();
unsigned long p,q,n,m,M,e,d,i,C,M1;
cout<<"Enter value of P : ";
cin>>p;
cout<<"Enter value of Q : ";
cin>>q;
n=p*q;
m=(p-1)*(q-1);
for(e=1;e {
if(m%e!=0)
break;
}
d=0;
do
{
d++;
i=(((e*d)-1)%m);
}while(i!=0);
cout<<"e : "< cout<<"d : "< cout<<"Enter value of M : ";
cin>>M;
C=pow(M,e);
C=C%n;
cout<<"Encryption C : "<
M1=pow(C,d);
M1=M1%n;
cout<<"Decryption M1 : "<
getch();
}

No comments: