Question
(whoever answers can you state what compiler you use to compile) This c++ program must randomly find two unique prime numbers and must assure that
(whoever answers can you state what compiler you use to compile)
This c++ program must randomly find two unique prime numbers and must assure that numbers are prime
It should perform the calculations to create the public and private keys. The calculations are as follows:
1. Choose two random prime numbers. (In the real algorithm, you would choose extremely large prime numbers which, in itself, canbe a challenge.) For this problem, choose prime numbers that are less than 100. Call these numbers p and q.
2. Calculate n = p q
3. Calculate the totient t, such that t=(p-1)(q-1)
4. Choose an integer e such that 1 < e< t and e and t have no common integer factors other than 1.
5. Compute d such that de 1 mod t. In other words, d e= 1 + an integer multiple of t.
6. The public key is the pair (e, n). The private key is the paid (d, n).
7. Encryption formula is: C= Pemod(n) Decryption formula is: P= Cdmod(n)
Must create two files, pub.key and priv.key. The two files should contain the two relevant numbers separated by a space on a single line (e.g. 3 33) where 3 is dand 33is n.
Must create two files, pub.key and priv.key. The two files should contain the two relevant numbers separated by a space on a single line (e.g. 3 33) where 3 is dand 33is n.
Program #2 (called encrypt.cpp) will take as input a public key and short plaintext program and output cipher text.
Must read the public key from the file pub.key Must take as input an integer between 1 and 50 (this will be the original plain text message) Must output ciphertext
Program #3 (called decrypt.cpp) will take as input a private key and ciphertext and output plaintext.
Must read private key from the file priv.key
Must take as input ciphertext output from program #2
Must output decrypted text
Here is an example to go off of for the first program.
#include
using namespace std;
//to find gcd int gcd(int a, int h) { int temp; while(1) { temp = a%h; if(temp==0) return h; a = h; h = temp; } }
int main() { //2 random prime numbers double p = 3; double q = 7; double n=p*q; double count; double totient = (p-1)*(q-1);
//public key //e stands for encrypt double e=2;
//for checking co-prime which satisfies e>1 while(e //private key //d stands for decrypt double d; //k can be any arbitrary value double k = 2; //choosing d such that it satisfies d*e = 1 + k * totient d = (1 + (k*totient))/e; double msg = 12; double c = pow(msg,e); double m = pow(c,d); c=fmod(c,n); m=fmod(m,n); cout<<"Message data = "< There are 3 Steps involved in it See step-by-step solutions with expert insights and AI powered tools for academic successStep by Step Solution
Step: 1
Get Instant Access to Expert-Tailored Solutions
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started