Back to Projects

RSA Encryption in Python

From-scratch RSA implementation in Python, focusing on cryptographic fundamentals and secure key generation.

Python Cybersecurity

Project Overview

A from-scratch implementation of the RSA public-key encryption algorithm in pure Python 3, built to understand how modern cryptographic systems work under the hood.

Rather than relying on existing crypto libraries, this project focuses on implementing the core mathematical and algorithmic components behind RSA, including prime generation, key derivation, and modular arithmetic.

What This Demonstrates

  • Understanding of public-key cryptography fundamentals
  • Ability to translate mathematical concepts into working code
  • Comfort working close to the language runtime without abstractions
  • Security awareness relevant to backend and full-stack systems

Core Components

  • Cryptographically secure randomness using secrets.SystemRandom
  • Probabilistic prime generation via Miller–Rabin primality testing
  • Extended Euclidean algorithm for modular inverse calculation
  • RSA key generation, encryption, and decryption implemented end-to-end

Technical Highlights

  • Generates large prime numbers and derives public/private key pairs
  • Implements modular exponentiation for encryption and decryption
  • Separates key generation logic from encryption operations
  • Uses only Python standard libraries to expose underlying mechanics

Learning Outcomes

This project strengthened my understanding of:

  • Number theory and modular arithmetic
  • Cryptographic key generation and validation
  • Secure randomness and probabilistic algorithms
  • Writing correct, testable low-level Python code

While not intended for production use, this implementation provided a strong foundation for reasoning about security-critical systems in real-world applications.

Related Projects