Question: Please implement the RSA encryption and decryption algorithm from scratch. RSA is an asymmetric cryptographic algorithm that uses two keys a public key for encryption

Please implement the RSA encryption and decryption algorithm from scratch. RSA is an asymmetric cryptographic algorithm that uses two keysa public key for encryption and a private key for decryption. Your implementation should be able to:
1. Compute a public key (encryption key) and the private key (decryption key) using the Extended Euclidean Algorithm.
2. Encrypt a message using the public key.
3. Decrypt the message using the private key.
Here are some key requirements for your implementation. Please READ CAREFULLY:
1. Prime Numbers:
Use two small prime numbers for p and q, both smaller than 100. You can directly assign the two prime numbers, so no prime generation is needed in your code.
You can use the values p =61 and q =83 in your code.
2. Public Key:
You can use e=17 as the public exponent.
3. Key Calculation:
Compute the private key d using the Extended Euclidean Algorithm (EEA).
4. Fast Exponentiation:
Implement the square-and-multiply algorithm to efficiently compute modular exponentiation for both encryption and decryption processes.
5. Encryption and Decryption:
Use the formula c = me modn for encryption, where mmm is the plaintext message.
For decryption, use m = cd modn to retrieve the original message.
6. Test Case:
Provide an example test case with a numerical message m=65 to verify both encryption and decryption. Here is the test case in Python. You can adjust it to any other language.
# Example usage
p =61
q =83
# Public key generation
public_key, private_key = generate_keys(p, q)
# Encrypting a message
message =65 # Example plaintext message
ciphertext = encrypt(message, public_key)
print(f"Encrypted message: {ciphertext}")
# Decrypting the message
decrypted_message = decrypt(ciphertext, private_key)
print(f"Decrypted message: {decrypted_message}")
Report Requirements:
Your report should document the procedures and implementation of RSA, including key generation, encryption, decryption, and fast exponentiation. Please show your understanding of the RSA algorithm

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!