Generate a real RSA keypair, encrypt a message, and decrypt it -- using this project's own from-scratch implementation (rsa/keygen.py, rsa/core.py, rsa/primes.py), not a library.
This is textbook RSA (no OAEP padding) at an educational key size. It's deterministic and malleable by design, so the weaknesses are visible -- never use output from this page to protect real data. See Security & Limitations.
0. How this actually works, step by step
Step 1 of 5: Generate keys. Pick two secret primes, multiply them, and derive a public/private exponent pair from the result.
showing an example — generate your own key in step 1 below and this updates automatically
p = 3q = 11
N = p × q = 33
φ(N) = 2 × 10 = 20
e = 3 (public)
d = 7 (private — the modular inverse of e)
01Pick two secret primes, multiply them, and derive a public/private exponent pair from the result.
The actual code behind this step
rsa/keygen.py:41-46hover a dotted line for what it does
def mod_inverse(a: int, m: int) -> int:"""Modular inverse of a mod m via extended Euclidean algorithm."""g, x, _ = extended_gcd(a % m, m)if g != 1:raise ValueError(f"{a} has no inverse mod {m} (gcd = {g})")return x % m
1. Generate a keypair
2. Encrypt with the public key (N, e)
-- applied per byte-block of your message.
Generate a keypair first.
3. Decrypt with the private key (N, d)
Encrypt a message first.