Skip to content

Commit

Permalink
Updated RSA-Code.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
nadinCodeHat committed Mar 14, 2021
1 parent a710181 commit 4c5a8a4
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions RSA-Code/RSA-Code.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,40 @@
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
//Two Prime Numbers
int x = 73 , y = 97;
int n = x * y;
double x = 73 , y = 97;
double n = x * y;

//Totient function (phi)
int phi = (x - 1) * (y - 1);
double phi = (x - 1) * (y - 1);

//e value co-prime of phi such that 1 < e < phi(n)
int e = 67;
//public key
double encrypt = 67;

//Calculate d such that e.d = 1 mod phi(n)
//pair (n,d) makes up the private key
//private key
double decrypt = fmod(1 / encrypt, phi);

//Plain Text
double message = 346;

//Encrypt the message
double encrypted_message = pow(message, encrypt);

//Decrypt the message
double decryped_message = pow(encrypted_message, decrypt);

encrypted_message = fmod(encrypted_message, n);
decryped_message = fmod(decryped_message, n);

cout << "Plain Text: " << message<<"\n";
cout << "Encrypted Text: " << encrypted_message << "\n";
cout << "Decrypted Text: " << decryped_message;

return 0;
}

0 comments on commit 4c5a8a4

Please sign in to comment.