2RSA Encryption encryption scheme. It uses the folowing wep 1. Iflware you to wn
ID: 3757514 • Letter: 2
Question
2RSA Encryption encryption scheme. It uses the folowing wep 1. Iflware you to wnd mr an encrypted m (we'll use 11 and 17 for this numple, athoughte prims actually uned are much langer) and two mlevely lage prime imbers p and q ege-3works since g3-13-017-1-1 3 Isend you e and n 4 To send me an encrypeed message you take your message assign numerical eqaivalents to each The real algorithm actually sakes groups eether thun single leners at a time; however, we are asking you to simplity this by encoding each er separately Exanple 9 20 15 19' mod 187 127 0 mod 187-4 15' mod 187 " 6 16' mod 187169 Wirite two function L A function checkepa tha given e and prime mumbers p and g checks whether godje. (p- 1- 1)-1(Yocan assume p and qae prime hene)He we your god function from the previous peoblem 2. A function char to number tha takes a n upecane lphabetic characte and uns an integee Once you gnt all these functions wim wite a min gam thut does the following it firnt anks the user to they do not, te program should priou an eror g and minate. If ehey do, the progm should ank char to number function, encode each uning the ollowing encode function, and print out the resub Hee is the code function int encode(int a int e,int m) Example 1 Input e, p. and q511 27 GCD of e and (p-)q-1) is not Esample 2 Input e, P, and 9:3 11 27 Input four upper case letters:STOP The encoding of STOP S 127 146 9 369 Esample 3 Input e, P. and q: 3 11 7 Input four upper case lettersSNOw The encoding of SNOW i5 127 126 9 12 Input e, p. and q:519 23 Please input four upper case letters: SKIS The encoding of SKISs 57 235 54 57 Note that this peogram will only work with smuall vala ofe.pndq (whut hppens id you try to encode STOoPwthe, p and g being 11,1nd 31, pectively? whyExplanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
int GCD(int a,int b);
bool check_epq(int e,int p,int q);
int char_to_number(char kitu);
int encode(int a, int e, int n);
int main()
{
char chon,a,b,c,d;
int e,p,q;
do{
cout<<"Input e, p, and q : ";
cin>>e>>p>>q;
int n=p*q;
if (check_epq(e,p,q))
{
cout<<"Input four upper case letters : ";
cin>>a>>b>>c>>d;
cout<<"The encoding of "<<a<<b<<c<<d<<" is ";
cout<<encode(a,e,n)<<" ";
cout<<encode(b,e,n)<<" ";
cout<<encode(c,e,n)<<" ";
cout<<encode(d,e,n)<<endl;
}
else{
cout<<"GCD of e and (p-1)*(q-1) is not 1 ";
}
cout<<"Continue? (y/n): ";
cin>>chon;
}
while (chon!='n');
return 0;
}
//==================================================================================
int GCD(int a, int b)
{
if (b==0) return a;
else return GCD(b,a%b);
}
//==================================================================================
bool check_epq(int e, int p, int q)
{
if (GCD(e,(p-1)*(q-1))==1) return true;
else return false;
}
//==================================================================================
int char_to_number(char kitu)
{
return (int(kitu)-65+1);//Ky tu A trong bang ASCII co so hieu la 65.
}
//==================================================================================
int encode(int a, int e, int n)
{
return ((int)(pow(char_to_number(a), e)) % n);
}
//==================================================================================
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.