Question: In this problem, you will implement the RSA cryptosystem in Python, the most popular public - key cryptosystem used for secure data transmission. Remember that

In this problem, you will implement the RSA cryptosystem in Python, the most popular public-key cryptosystem used for secure data transmission. Remember that you need four parameters to implement this (\( p, q, e \) and \( d \)) as explained in the class.
Things to do:
1. Prime Number Selection:
- You are given a text file 'primes.txt' that contains prime numbers between 100 and 1000.
- Randomly select two prime numbers p and q from this file.
2. RSA Key Generation:
- Write a function rsa_keygen.
- Calculate \(\mathrm{n}=\mathrm{p}^{*}\mathrm{q}\), where n is the modulus for both the public and private keys.
- Calculate Euler's Totient function, \(\varphi(n)=(p-1)*(q-1)\).
- Set \(\mathbf{=}7\).
- Compute the private key d using the Extended Euclidean Algorithm (\( d \equiv e^{\wedge}(-1)\bmod \phi(n)\)). A sample python method (ExEuclid.py) for the Extended Euclidean Algorithm is included in the assignment where the output x represents d (See this \(\underline{l i n k}\) for explanation).
3. Encryption
- Write a function rsa_encrypt that converts each character of the plaintext "Computer" to its ASCII value (May use ord () in Python).
- Calculate the Ciphertext: \( C=M^{e}\bmod n \)
4. Decryption
- Write a function rsa_decrypt that calculates the Plaintext: \( M=C^{d}\bmod n \)
- Convert the decrypted ASCII values back to characters to recover the original message.
5. Displaying Results
- Display the generated public and private keys.
- Show the encrypted and decrypted version of the plaintext "Computer".
Additional Notes:
- You may not use built-in Python RSA or Stream Cipher implementations.
- You may write helper functions/methods if needed. For example, you may need to write a function to calculate the totient value for RSA.
- Use good coding practice. Use comments to make your code readable.
In this problem, you will implement the RSA

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!