- RSA (Rivest–Shamir–Adleman) is an algorithm used by modern computers to encrypt and decrypt messages.
- It is an asymmetric cryptographic algorithm.
- Asymmetric means that there are two different keys.
- This is also called public key cryptography, because one of the keys can be given to anyone.
EXAMPLE :-
#include<iostream>
#include<math.h>
using namespace std;
int gcd(int a, int b) {
int s;
while(1) {
s= a%b;
if(s==0)
return b;
a = b;
b= s;
}
}
int main() {
double x = 3;
double y = 5;
double n=x*y;
double track;
double phi= (x-1)*(y-1);
double e=11;
while(e<phi) {
track = gcd(e,phi);
if(track==1)
break;
else
e++;
}
double d1=1/e;
double d=fmod(d1,phi);
double message = 13;
double c = pow(message,e);
double m = pow(c,d);
c=fmod(c,n);
m=fmod(m,n);
cout<<"Original Message = "<<message;
cout<<"\n"<<"x = "<<x;
cout<<"\n"<<"y = "<<y;
cout<<"\n"<<"n = xy = "<<n;
cout<<"\n"<<"phi = "<<phi;
cout<<"\n"<<"e = "<<e;
cout<<"\n"<<"d = "<<d;
cout<<"\n"<<"Encrypted message = "<<c;
cout<<"\n"<<"Decrypted message = "<<m;
return 0;
}
OUTPUT
Original Message = 13
x = 3
y = 5
n = xy = 15
phi = 8
e = 11
d = 0.0909091
Encrypted message = 7
Decrypted message = 13
No comments:
Post a Comment
Please do not any spam link in Comment Box