RSA
RSA
RSA Algorithm is used to encrypt and decrypt data in modern computer systems and
other electronic devices. RSA algorithm is an asymmetric cryptographic algorithm as it creates 2
different keys for the purpose of encryption and decryption. It is public key cryptography as one
of the keys involved is made public. RSA stands for Ron Rivest, Adi Shamir and Leonard
Adleman who first publicly described it in 1978.
RSA makes use of prime numbers (arbitrary large numbers) to function. The public key
is made available publicly (means to everyone) and only the person having the private key with
them can decrypt the original message.
RSA involves use of public and private key for its operation. The keys are generated using the
following steps:-
Page 1
RSA algorithm to encrypt and decrypt
Program
#include<stdio.h>
#include<math.h>
return(x<y?x:y);
return(x>y?x:y);
while(x>0)
if ((int)(fmodl(x,2))==1)
Page 2
RSA algorithm to encrypt and decrypt
r=fmodl((r*a),n);
a=fmodl((a*a),n);
x/=2;
return(r); }
int main()
} while(p==q);
n=p*q; phi=(p-1)*(q-1);
do{
for(d=1;d<phi;++d)
if(fmod((e*d),phi)==1)
break;
Page 3
RSA algorithm to encrypt and decrypt
scanf(" %Lf",&ms);
es=modexp(ms,e,n);
ds=modexp(es,d,n);
return(0);
Page 4