Question

This assignment is a rsa project. please help me with it? Generate two prime numbers at...

This assignment is a rsa project. please help me with it? Generate two prime numbers at least 1 million. These are p and q. n = pxq.

Show how and show p and q

* Find d and e . Show how and show d and e.

* Encrypt message 100. use the above results. show this number. Programming language! C++

Please add some comments to the program. Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

#include<iostream>
#include<math.h>

using namespace std;

int gcd(int a,int b){ //to fing gcd of two numbers
   int t; // variable to store remainder
   while(1){ // infinite loop
       t=a%b; // finding remainder of two numbers
       if(t==0){ // if remainder is zero then we found gcd
           return b;
       }
       a=b;
       b=t;
   }
}
int main(){

double p=103; // two prime numbers
double q=107;
double n=p*q; // calculating n value
double phi=(p-1)*(q-1); //calculating phi value
double e=2;
while (e<phi){ // finding e value where e<n such that gcd(e,phi)=1
   if(gcd(e,phi)==1){ // if gcd of two numbers is 1 then store i value into e
       break;
   }
   else{
       e++;
   }
}
double d1=1/e; // claculating d value
double d=fmod(d1,phi);

double message=100;
double c=pow(message,e); //cypher text or encrypted message variable
double m=pow(c,d); //decrypt variable to decrypt encrypted message
c=fmod(c,n);
m=fmod(m,n);

cout<<"p value: "<<p<<endl;
cout<<"q value: "<<q<<endl;
cout<<"e value: "<<e<<endl;
cout<<"d value: "<<d<<endl;
cout<<"n value: "<<n<<endl;
cout<<"phi value: "<<phi<<endl;
cout<<"e value: "<<e<<endl;
cout<<"d value: "<<d<<endl;
cout<<"Original Message: "<<message<<endl;
cout<<"Encrypted message: "<<c<<endl;
cout<<"Decrypted message: "<<m<<endl;
}

Output:

p value: 103 q value: 107 e value: 5 d value: 0.2 n value: 11021 phi value: 10812 e value: 5 d value: 0.2 Original Message: 1

Add a comment
Know the answer?
Add Answer to:
This assignment is a rsa project. please help me with it? Generate two prime numbers at...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT