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:
Compute a public key encryption key and the private key decryption key using the Extended Euclidean Algorithm.
Encrypt a message using the public key.
Decrypt the message using the private key.
Here are some key requirements for your implementation. Please READ CAREFULLY:
Prime Numbers:
Use two small prime numbers for p and q both smaller than You can directly assign the two prime numbers, so no prime generation is needed in your code.
You can use the values p and q in your code.
Public Key:
You can use e as the public exponent.
Key Calculation:
Compute the private key d using the Extended Euclidean Algorithm EEA
Fast Exponentiation:
Implement the squareandmultiply algorithm to efficiently compute modular exponentiation for both encryption and decryption processes.
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.
Test Case:
Provide an example test case with a numerical message m to verify both encryption and decryption. Here is the test case in Python. You can adjust it to any other language.
# Example usage
p
q
# Public key generation
publickey, privatekey generatekeysp q
# Encrypting a message
message # Example plaintext message
ciphertext encryptmessage publickey
printfEncrypted message: ciphertext
# Decrypting the message
decryptedmessage decryptciphertext privatekey
printfDecrypted message: decryptedmessage
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
