This repository contains a Python implementation of Textbook RSA using Miller-Rabin primality test.
If you don't know how RSA works, take a look at this book: CORMEN, Thomas H. et al. Introduction to algorithms. MIT press, 2009.
You'll need Python 3.x x64 to be able to run theses projects.
If you do not have Python installed yet, it is recommended that you install the Anaconda distribution of Python, which has almost all packages required in these project.
You can also install Python 3.x x64 from here
-
Clone the repository and navigate to the downloaded folder.
git clone https://github.com/lccasagrande/Textbook-RSA.git cd Textbook-RSA
-
Install required packages:
pip install -e .
Or:
pip install -e . --user
-
Navigate to the src folder:
cd src
-
Generate Keys:
python keygen.py -v 1 --output_dir "../test/" --key_size 2048
-
Encrypt file
python encrypt.py -v 1 --key "../test/public_key.der" --file "../test/text.txt"
-
Decrypt File
python decrypt.py -v 1 --key "../test/private_key.der" --file "../test/text.txt"
-
Optional: It's possible to use the Pollard's Rho algorithm to break the RSA key. Do not use it with large key sizes, 32 bits should be a good first try.
- Generate key with 32 bits:
python keygen.py -v 1 --output_dir "../test/" --key_size 32
- Encrypt file
python encrypt.py -v 1 --key "../test/public_key.der" --file "../test/text.txt"
- Run Pollard's Rho
python pollard_rho.py -v 1 --public_key "../test/public_key.der" --output_dir "../test/"
- Decrypt file
python decrypt.py -v 1 --key "../test/pollard_private_key.der" --file "../test/text.txt"