A Python-based educational tool demonstrating how the Rivest-Shamir-Adleman (RSA) algorithm works under the hood, including prime generation, key creation, and block-based encryption/decryption.
- Extended Euclidean Algorithm
- Modular inverse computation
- Miller–Rabin probabilistic primality test
- Random and strong prime generation
- RSA key pair generation (1024-bit)
- Block-based encryption and decryption
This project is for learning and demonstration purposes only. It is not intended for securing real communications. In particular:
- No padding scheme (e.g. OAEP) is used, making raw RSA encryption vulnerable to several attacks.
- The generated
pubKey.jsonandprivKey.jsonfiles contain key material and are excluded from version control - 1024-bit keys are below modern security recommendations; production RSA uses 2048-bit or larger.
Python 3.8+. No external packages required (see requirements.txt).
git clone https://github.com/colesjunge/rsaSimulator.git
cd rsaSimulatorNo further setup is needed.
python rsaMain.pyYou'll see an explanation of how RSA works, followed by a menu:
RSA Encryption - MAIN MENU
1. Generate New Key Pair
2. Encrypt a Message
3. Decrypt a Message
4. Show RSA Information
5. Exit
Generate a key pair first (option 1), then encrypt (option 2) and decrypt (option 3) freely. Copy the encrypted block output and paste it back in when decrypting.
- Generate two large primes
pandq - Compute
n = p * qandφ(n) = (p-1)(q-1) - Choose public exponent
e(typically 65537) wheregcd(e, φ(n)) = 1 - Compute private exponent
dsuch thate * d ≡ 1 (mod φ(n)) - Encrypt:
c = m^e mod n - Decrypt:
m = c^d mod n
.
├── rsaMain.py # Entry point / interactive menu
├── rsaAlgorithmFunctions.py # Core RSA math
├── rsaDisplayGenFunctions.py # I/O and console display logic
├── pubKey.json # Generated at runtime - not tracked in git
├── privKey.json # Generated at runtime - not tracked in git
├── requirements.txt
└── README.md
MIT — see LICENSE for details.
Cole Junge