In this assignment, you will use RSA functions to discover the secret behind the mysterious sus.txt
and rev.txt
files.
The content of the file sus.txt
is encrypted using a public key. Your task is to find the correct
private key out of 20 possible keys in the key_pairs
directory to decrypt that message.
The starter code is in rsa.py
. Complete it and submit only rsa.py
to Gradescope.
a. Generate public and private keys
b. Find the right key and decrypt the message in sus.txt
c. Sign a message and verify it
d. Find Miss Reveille's key pair that she used to sign rev.txt
q. Quit
- Generate a public/private key pair using 2048 bits key length using the function
generate_keys()
. Save the public and private keys in two files. - Encrypt a plaintext using the function
encrypt_message()
. - Decrypt a cyphertext using the function
decrypt_message()
.
- Write the function
find_decrypt_key()
, to find which key in thekey_pairs
directory can decrypt thesus.txt
message. - Once you find the right key, decrypt the file
sus.txt
. - Write the decrypted message in the file
sus_decrypted.txt
. Note: You should realize it was written by Miss Rev. - Your next task is to find Miss Rev's signature key in the
key_pairs
directory. This is not the same key as the one used in part b.
Write the functions sign_message()
and verify_message()
to sign and verify a message, respectively.
- Sign a message using the private key from part a.1.
- Write the signature in a file
signed_msg.txt
. - Verify the signature using the public key from part a.1.
Find the correct Reveille's signature by verifying the signature of the message in sus_decrypted.txt
.
Use a method similar to part b to find which key is used to sign the messagerev.txt
.
We need pycryptodome to run this program. If not installed, to install pycryptodome in Python 3, type:
make install
or
python3 -m pip install pycryptodome
To run the program, type:
make run
To clean up the files generated by the program, type:
make clean
- A small starter video here: https://youtu.be/4Le42qqSZeA
- You only need read(
r
) and write(w
) access to the files. Use theb
flag when opening the files along withr
andw
. Read more at: https://www.programiz.com/python-programming/methods/built-in/open - In the key_pairs directory, the public key suffix is
_pub
, and the private key suffix is_priv
. - Your program will be manually tested for correctness with additional test cases.
- Your program should execute with no errors and warnings.