Question

forehand e receiver creates a public key and a secret key as follows. Generate two distinct primes, p andq. Since they can be used to generate the secret key, they must be kept hidden. Let n-pg, phi(n) ((p-1)*(q-1) Select an integer e such that gcd(e, (p-100g-1))-1. The public key is the pair (e,n). This should be distributed widely. Compute d such that d-l(mod (p-1)(q-1). This can be done using the pulverizer. The secret key is the pair (d.n). This should be kept hidden Encoding: iven a messagem, the sender first checks thatgcd(m,n)-1.The sender then encrypts message m to produce m using the public key: ing: receiver decrypts message m back to message m using the secret key: mrem(mY.n) Develop an application that will implement the RSA cryptosystem. Inputs: 1. Two prime numbers: p andg 2. The message to be encrypted (this is an integer): m Required features:+ 1. An independentmethod that could be used to compute gcdof two numbers using the Euclidean algorithm: geda,b)=gcd(b, rem(a,b))- 2. Ability to find the values of two integers s and tSuch that gcd(a,b) = sa +tb . This should be implemented as an independent method. This method is the Pulverizer or the Extended Euclidean algorithm 3. Compute the public and private keys. You need to think about an intelligent way to utilize the routines that you have developed in Step 1 and Step 2. 4. Perform encryption and decryption. 5. The application should print the encrypted message on the output screen and should also verify that decryption actually reproduce the original message 6. Your application should NOT be using any built in libraries. 7. Use the (%) operator to compute the remainder,d 8. You may compute rem a.b) using successive squaring as explained in an example on page 107 of the textbook. For example, all the congruences below hold modulo 17- 62 362 2 615-8-64-62-6-16-42-#23Use C++

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

Answer is as follwos :

The code in C++ :

#include <iostream>
#include<cmath>

using namespace std;
int gcd(int a, int h)
{
int temp;
while (1)
{
temp = a%h;
if (temp == 0)
return h;
a = h;
h = temp;
}
}
int main()
{
// Two random prime numbers
int p ;
int q ;
cout << "Enter p and q ";
cin >> p >> q ;

// First part of public key:
int n = p*q;

// Finding other part of public key.
// e stands for encrypt
int e = 2;
int phi = (p-1)*(q-1);
while (e < phi)
{
// e must be co-prime to phi and
// smaller than phi.
if (gcd(e, phi)==1)
break;
else
e++;
}

// Private key (d stands for decrypt)
// choosing d such that it satisfies
// d*e = 1 + k * totient
int k = 2; // A constant value
int d = (1 + (k*phi))/e;

// Message to be encrypted
int msg;
cout << "Enter Message : " ;
cin >> msg ;
  

// Encryption c = (msg ^ e) % n
int c = pow(msg, e);
c = fmod(c, n);
cout << "\nEncrypted data :" << c;

// Decryption m = (c ^ d) % n
int m = pow(c, d);
m = fmod(m, n);
cout << "\nDecrypted data :" << m;

return 0;
}

Output Screenshot :

Enter p and q 3 7 Enter Message 12 Encrypted data :3 Decrypted data :12

if there is any query please ask in comments...

Add a comment
Know the answer?
Add Answer to:
Use C++ forehand e receiver creates a public key and a secret key as follows. Generate...
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
  • For the RSA encryption algorithm , do the following (a) Use p=257,q=337(n=pq=86609),b=(p-1)(q-1)=86016. Gcd(E,b)=1, choose E=17, find...

    For the RSA encryption algorithm , do the following (a) Use p=257,q=337(n=pq=86609),b=(p-1)(q-1)=86016. Gcd(E,b)=1, choose E=17, find D, the number which has to be used for decryption, using Extended Euclidean Algorithm (b) One would like to send the simple message represented by 18537. What is the message which will be sent? (c) Decrypt this encrypted message to recover the original message.

  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • The Diffie-Hellman public-key encryption algorithm is an alternative key exchange algorithm that is used by protocols...

    The Diffie-Hellman public-key encryption algorithm is an alternative key exchange algorithm that is used by protocols such as IPSec for communicating parties to agree on a shared key. The DH algorithm makes use of a large prime number p and another large number, g that is less than p. Both p and g are made public (so that an attacker would know them). In DH, Alice and Bob each independently choose secret keys, ?? and ??, respectively. Alice then computes...

  • prime factorization. Assume that zoy wants to send a message to sam. sam generates public and...

    prime factorization. Assume that zoy wants to send a message to sam. sam generates public and private keys using RSA Encryption algorithm and publishes the public key (n=4717, e=19). zoy has a secret message M to send. Nobody knows the value of M. She encrypts the message M using the public key and sends the encrypted message C=1466 to sam. alex is an intruder who knows RSA and prime factorization well. She captures the encrypted message C=1466. She also has...

  • If a public key has the value (e, n)-(13,77) (a) what is the totient of n,...

    If a public key has the value (e, n)-(13,77) (a) what is the totient of n, or (n)? (b) Based on the answer from part (a), what is the value of the private key d? (Hint: Remember that d * e-1 mod (n), and that d < ф(n)) You may use an exhaustive search or the Modified Euclidean Algorithm for this. Show all steps performed. For both (c) and (d), use the Modular Power Algorithm, showing all steps along the...

  • Question 2 (compulsory) (a) Explain the operation of the RSA public-key cryptosystem (b) Illustra...

    Question 2 (compulsory) (a) Explain the operation of the RSA public-key cryptosystem (b) Illustrate your explanation by using the prim es p 13 and q 17 and secret decryption key d 103 to (i) decrypt the ciphertext z2; (ii) compute the public encryption key e corresponding to d (ii) encrypt the plaintext m-. (c) Discuss the security of the RSA public-key cryptosystem Question 2 (compulsory) (a) Explain the operation of the RSA public-key cryptosystem (b) Illustrate your explanation by using...

  • Computing RSA by hand. Let p = 13, q = 23, e = 17 be your...

    Computing RSA by hand. Let p = 13, q = 23, e = 17 be your initial parameters. You may use a calculator for this problem, but you should show all intermediate results. Key generation: Compute N and Phi(N). Compute the private key k_p = d = e^-1 mod Phi(N) using the extended Euclidean algorithm. Show all intermediate results. Encryption: Encrypt the message m = 31 by applying the square and multiply algorithm (first, transform the exponent to binary representation)....

  • 2. Alice is a student in CSE20. Having learned about the RSA cryptosystem in class, she...

    2. Alice is a student in CSE20. Having learned about the RSA cryptosystem in class, she decides to set-up her own public key as follows. She chooses the primes p=563 and q = 383, so that the modulus is N = 21 5629. She also chooses the encryption key e-49. She posts the num- bers N = 215629 and e-49 to her website. Bob, who is in love with Alice, desires to send her messages every hour. To do so,...

  • Write a program in Python implement the RSA algorithm for cryptography. Set up: 1.Choose two large...

    Write a program in Python implement the RSA algorithm for cryptography. Set up: 1.Choose two large primes, p and q. (There are a number of sites on-line where you can find large primes.) 2.Compute n = p * q, and Φ = (p-1)(q-1). 3.Select an integer e, with 1 < e < Φ , gcd(e, Φ) = 1. 4.Compute the integer d, 1 < d < Φ such that ed ≡ 1 (mod Φ). The numbers e and d are...

  • In this question, we will use the following notations: PU and PR are the Public and...

    In this question, we will use the following notations: PU and PR are the Public and its corresponding Private keys K is a symmetric Key. 1. [M]K message M is decrypted with K MjPu: message M is encrypted/verified with P is the correspondin is a Message an Cipher M h: message M is encrypted with K. H(M): the hash of message M. Assume that Bob and Alice agree on a shared secret K. Bob wants to authenticate himself to Alice...

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
ADVERTISEMENT