! Educational demonstration only. Keys, moduli, and RSA sizes here are intentionally tiny so classical/quantum attacks finish in seconds — today's classical hardware cannot run Shor's algorithm against real production RSA keys. See Security & Limitations.
Shor's Lab

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)
N=pq,φ(N)=(p1)(q1),ed1(modφ(N))N = pq,\quad \varphi(N) = (p-1)(q-1),\quad ed \equiv 1 \pmod{\varphi(N)}

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-46
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)

c=me  mod  Nc = m^e \; \text{mod} \; N -- applied per byte-block of your message.

Generate a keypair first.

3. Decrypt with the private key (N, d)

m=cd  mod  Nm = c^d \; \text{mod} \; N

Encrypt a message first.