A Python-based exploration of RSA public-key cryptography and integer factorization. Includes tools to generate large primes, create RSA key pairs, encrypt/decrypt files, and test factorization vulnerabilities using Brute Force and Fermat's method. Created as a high school final project.
This repository contains my final high school project, focusing on the mechanics of RSA public-key cryptography. It is a hands-on implementation of how RSA encryption works under the hood, accompanied by mathematical factorization algorithms designed to test how these keys can be broken.
makePublicPrivateKeys.py: Generates RSA public and private key files using randomly generated large primes.publicKeyCipher.py: Encrypts standard text into block integers and decrypts it back to readable text using the generated key files.
primeNum.py: Handles prime number logic, including a Sieve of Eratosthenes and the Rabin-Miller primality test for generating secure keys.cryptomath.py: Contains essential mathematical functions, such as finding the Greatest Common Divisor (Euclid's Algorithm) and modular inverses (Extended Euclidean Algorithm).
bruteForce.py: A brute-force trial division script with a timer to test how long it takes to factorize a given modulus.fermat.py&fermat.sage: Implementations of Fermat's factorization method in both Python and SageMath to efficiently find factors of odd positive integers.
- Generate Keys: Run
makePublicPrivateKeys.pyto create your public (_pubkey.txt) and private (_privkey.txt) keypair files. - Encrypt & Decrypt: Run
publicKeyCipher.pyin the same directory as your key files. You can toggle themodevariable inside the script to either'encrypt'a message to a file or'decrypt'an existing file. - Test Factorization: Run
bruteForce.pyorfermat.pyto time how long it takes your machine to factorize large integers.
- Core cryptography logic and mathematical utilities are based on the BSD-licensed Cracking Codes with Python by Al Sweigart.
- The Python implementation of Fermat's factorization was inspired by GeeksforGeeks.