This repository contains Lab 3 code exploring RSA key generation, encryption/decryption, simple cracking by factoring the modulus, and timing experiments at small prime bit sizes. Core Python files:
lab3-part1.py– Generates an RSA key pair and demonstrates encrypt/decrypt in both directions.lab3-part2.py– Factors a provided modulus withsympy.primefactorsto recover the private key and decrypt a ciphertext.lab3-part3.py– Times prime generation + factoring across several bit sizes and plots results.prime.py– Miller–Rabin primality test and prime generation helper.
Two supplemental HTML pages (index.html, all-in-one.html) were auto-generated by an AI assistant to provide:
- An interactive in-browser RSA demo (small, insecure toy keys) mirroring the lab logic.
- Embedded source code, images, and the lab PDF for easy navigation.
- A light/dark theme toggle (default dark) persisted with
localStorage. - Visual badges marking the UI as AI-generated – the underlying Python lab code was not modified for functionality.
These pages are for demonstration and documentation only; they intentionally omit real-world RSA safeguards (padding/OAEP, large key sizes, constant-time operations, side-channel protections). Do not use the in-browser demo for any production or security purposes.
Install dependencies:
pip install sympy matplotlib
Example usage:
python lab3-part1.py 64
python lab3-part2.py
python lab3-part3.py
Increase the bit length for more realistic (but slower) key generation; factoring becomes rapidly infeasible beyond very small sizes with the naive approach used here.
- No padding (e.g., OAEP) is applied; raw RSA is malleable and not semantically secure.
- Factoring uses
sympy.primefactors, not advanced algorithms (Quadratic/Number Field Sieve). - Chosen exponents are standard (
e=65537) but key sizes are intentionally tiny for demonstration. - Timing plots reflect toy scales only.
The lab code is provided for educational purposes. Review individual file headers for any referenced sources (e.g., Miller–Rabin implementation).