1) Using any programming language of your choice implement the Key Generation pr
ID: 3915524 • Letter: 1
Question
1) Using any programming language of your choice implement the Key Generation procedure of the RSA algorithm 2) Specifications: The program should take two inputs, non-negative integers a, b, which will define a range within which two random prime numbers p, q will be generated by your program i.e. ap,qb). The program should select numbers randomly from the range [a,b] and test them for primality. It should continue to do this until it has found two prime numbers that are not equal. Tnhe progrom eoud utput threevalues 1) The publc key on ) 2) The pivate koy (n,d) 3) The values of p and q generated Please note that your program MUST use the code you implemented for Ass 1 and Ass 2. It should call the Rabin-Miller algorithm implementation to generate the p and q. And it should call the Extended Euclidean Algorithm implementation to generate the d i.e. the multiplicative inverse of e mod n Test 1. Use your code to generate public and private keys for a 100 and b 300. List the output of your code, with screenshots. 2. Based on your results what is the maximum value of the integer representation of a string that can be encrypted at once? What is the value of the Euler's Totient function for your value of n. Assuming A=1, B-2,--, Z-26, work through an example to show how the word 3. 4. AXES will be encoded using the results above. What is the ciphertext? 5. Work through an example of how the ciphertext above will be decrypted.Explanation / Answer
#include<iostream>
#include<math.h>
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<totient){
count = gcd(e,totient);
if(count==1)
break;
else
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 = "<<msg;
cout<<" "<<"p = "<<p;
cout<<" "<<"q = "<<q;
cout<<" "<<"n = pq = "<<n;
cout<<" "<<"totient = "<<totient;
cout<<" "<<"e = "<<e;
cout<<" "<<"d = "<<d;
cout<<" "<<"Encrypted data = "<<c;
cout<<" "<<"Original Message sent = "<<m;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.