Primearium Lab · Cryptography

Primes Guard Your Secrets

Multiplying two prime numbers takes a blink. Undoing that product can take longer than the age of the universe. Watch your browser race against growing primes, forge your own animated RSA padlock, and mix secret colors in plain sight.

Part 1 · The One-Way Street

Easy to Multiply. Brutal to Undo.

Give any computer two big primes and it multiplies them in microseconds. Hand it only the product n = p × q and ask for p and q back — even clever algorithms slam into an exponential wall.

Proven: multiplication is fast Observed: live in your browser Conjecture: no fast classical factorer

Live Browser Factoring Race

Your browser multiplies growing balanced semiprimes (16 to 96 bits), then tries to crack them using naive Trial Division and Pollard–Brent rho (from Primearium's primes.js) inside a Web Worker.

Ready. Click “Start Live Race” to watch Trial Division and Pollard's rho hit the wall.

  • Multiply p × q
  • Trial Division
  • Pollard's rho
  • GNFS (Estimate)
Size Semiprime n = p × q p × q Trial Div Pollard rho

Honest Extrapolation to RSA-2048

Estimate

Drag the key size up to real-world RSA-2048 (617 decimal digits). Every extrapolation below is an asymptotic single-core order-of-magnitude estimate — not a live measurement.

2048 bits ~617 digits

Multiply p × q

Proven

< 1 ms

Fast polynomial time — still instant even at 4096 bits.

Trial Division

Estimate

—

Checks up to √n ≈ 2^(b/2) divisors.

Pollard's rho

Estimate

—

Expected ~n^(1/4) ≈ 2^(b/4) steps (birthday paradox).

Best Classical (GNFS)

Estimate

—

Heuristic L[1/3] scaling anchored at RSA-250 (2020).

Try One Yourself: Snap Together & Crack

Generate two fresh primes of your chosen bit size, multiply them in a blink, then ask the Web Worker to split n back apart.

— × — = —

Click “Try to Crack n” to race Trial Division vs Pollard's rho on this semiprime.

Part 2 · Build Your Own RSA

Forge a Padlock Anyone Can Shut — Only You Can Open

Pick two small primes p and q, build a real working RSA keypair step by step, and watch each letter of a demo message transform with BigInt modular exponentiation.

Educational demo with tiny primes — runs 100% locally in your browser and stores nothing. Never type real passwords or personal data.
Prime presets:
1

Pick Two Secret Primes

Choose two different prime numbers. Keep them in your private workshop — never share them!

2

Multiply for Lock n & Secret φ(n)

n = p × q is the size of our number clock (public). φ(n) = (p − 1)(q − 1) counts numbers sharing no factors with n (secret!).

Public clock size n = p × q
3,233
Secret count φ(n) = (p − 1)(q − 1)
3,120
3

Pick Locking Exponent e

Pick any number e smaller than φ(n) that shares no common factor with φ(n) (gcd = 1). This goes on the outside of your padlock.

4

Forge Secret Key d

Find the special partner d so that e × d leaves remainder 1 when divided by φ(n). Only someone who knows φ(n) can find d easily!

Private key exponent d = e⁻¹ mod φ(n)
2,753
Check: (e × d) mod φ(n)
17 × 2753 = 15 × 3120 + 1 ≡ 1
Public Padlock — Share Freely
(n = 3233, e = 17)

Anyone can lock a number m by computing c = m^e mod n.

Private Key — Keep Secret!
(n = 3233, d = 2753)

Only you can unlock c back to m by computing m = c^d mod n.

Encrypt & Decrypt Letter by Letter

Each letter turns into its Unicode number m, rides through the modular clock to become ciphertext c, then unlocks right back to the original letter.

Under the Hood: BigInt & Fast Modular Exponentiation (Square-and-Multiply)

Step Bit of e Square (acc² mod n) If bit = 1, × m mod n

Part 3 · Diffie-Hellman Key Exchange

Create a Shared Secret While Everyone Listens

How can Alice and Bob agree on a secret key over a public wire when eavesdropper Eve hears every message? First see it with mixing paint — then with real prime-number clock math.

Proven: (g^b)^a ≡ (g^a)^b (mod p) Conjecture: discrete log is hard

1. Intuition: Mixing Paint Colors

Mixing two paints is easy; un-mixing them back into exact ingredients is nearly impossible. Alice and Bob mix their secret colors with a public base color, trade mixtures in front of Eve, and add their own secret color one last time.

Palettes:

Honest note: Paint is a metaphor for intuition — real computers don't mix pigments. Below is the exact modular arithmetic that makes Diffie-Hellman work on the internet.

2. The Real Math: Modular Exponentiation

Replace “base paint” with a public prime p and generator g. Mixing a secret number means raising to that power modulo p.

Public clock (p, g):
Proven primitive root

Alice (Private)

Sends public A: 5^6 mod 23 = 8

Computes secret: 19^6 mod 23 = 2

Public Wire (Eve Sees)

p = 23, g = 5, A = 8, B = 19

Eve sees (p, g, A, B). To steal the key, she must invert g^a mod p (the Discrete Logarithm Problem).

Bob (Private)

Sends public B: 5^15 mod 23 = 19

Computes secret: 8^15 mod 23 = 2

Part 4 · Research & Proofs

For Mathematicians: What Is Proven, Conjectured & Changing

Cryptography sits on a razor's edge between rock-solid number theory theorems and unproven complexity assumptions. Open any card below for exact statements and honest limits.

Proven Why RSA Always Works: Fermat's Little Theorem & Euler's Theorem

Fermat's Little Theorem (1640; proved by Euler, 1736): If p is prime and p ∤ a, then ap−1 ≡ 1 (mod p).

Euler's Theorem (1763): For any integer n ≥ 2 and any a with gcd(a, n) = 1, aφ(n) ≡ 1 (mod n).

Complete Proof that (me)d ≡ m (mod pq) for ALL integers m

Since ed ≡ 1 (mod (p−1)(q−1)), write ed = 1 + k(p−1)(q−1) for some integer k ≥ 1. Modulo p: if p ∣ m, then med ≡ 0 ≡ m (mod p). If p ∤ m, Fermat's Little Theorem gives mp−1 ≡ 1 (mod p), hence med = m · (mp−1)k(q−1) ≡ m · 1 = m (mod p). By symmetry, med ≡ m (mod q) in both cases. Because distinct primes satisfy gcd(p, q) = 1, the Chinese Remainder Theorem yields med ≡ m (mod pq). ∎

Real-world precision: Carmichael's function λ(n) = lcm(p−1, q−1) also suffices (used in PKCS#1 / FIPS 186-5). Moreover, production RSA never encrypts raw unpadded messages — randomized padding schemes (OAEP / PSS) are essential to prevent algebraic and chosen-ciphertext attacks.

Conjecture Is Factoring Truly Hard? The Unproven Assumption

No theorem proves that integer factorization lacks a fast classical algorithm. The security of RSA rests on an unproven hardness assumption: that no polynomial-time classical algorithm factors general semiprimes.

  • Proven: The decision version of factoring lies in NP ∩ coNP (using primality certificates or AKS primality in P). Thus factoring is widely believed not to be NP-complete (which would collapse NP = coNP).
  • Heuristic best classical algorithm: The General Number Field Sieve (GNFS) runs in conjectured sub-exponential time Ln[1/3, (64/9)1/3] = exp(((64/9)1/3 + o(1))(ln n)1/3(ln ln n)2/3).
  • Open question: Factoring n breaks RSA (Proven), but whether breaking RSA (finding e-th roots mod n) is always as hard as factoring n remains unproven in general.
  • Diffie-Hellman: Rests on the Discrete Logarithm Problem (DLP) and Computational/Decisional Diffie-Hellman (CDH/DDH) assumptions — likewise unproven.
Observed Fast Multiplication vs. Public Factoring Records

Multiplication (Proven): Two b-bit integers can be multiplied in O(b log b log log b) time (Schönhage–Strassen, 1971) and asymptotically O(b log b) (Harvey–van der Hoeven, 2019).

  • RSA-129 (1994): 129 decimal digits (426 bits) — factored via Quadratic Sieve.
  • RSA-768 (2009): 232 decimal digits (768 bits) — factored via GNFS (~1,500–2,000 CPU core-years).
  • RSA-250 (Feb 2020): 250 decimal digits (829 bits) — factored via GNFS / CADO-NFS by Boudot, Gaudry, Guillevic, Heninger, Thomé & Zimmermann (~2,700 CPU core-years). Largest public RSA challenge factored by GNFS known at writing (unverified citation beyond 2024).
Proven Observed Shor's Algorithm & Post-Quantum Cryptography (Honest, No Hype)

What is Proven (Peter Shor, 1994): A fault-tolerant quantum computer can find the period r of f(x) = ax mod n using the Quantum Fourier Transform in polynomial time Õ((log n)3), breaking both integer factoring (RSA) and discrete logarithms (Diffie-Hellman and elliptic-curve cryptography).

Observed Engineering Reality (No Hype): Today's noisy quantum processors cannot factor cryptographically relevant RSA keys. Published resource analyses (such as Gidney & Ekerå, 2021, and follow-up studies) estimate that factoring RSA-2048 requires thousands of error-corrected logical qubits — translating to millions of physical qubits with low error rates, a formidable engineering challenge still far from solved.

Why Upgrade Now? Under “harvest now, decrypt later,” sensitive encrypted traffic recorded today could be decrypted years later if large fault-tolerant quantum machines are built. Cryptographers therefore standardized Post-Quantum Cryptography (PQC) — including NIST's 2024 standards ML-KEM (lattice key encapsulation), ML-DSA (lattice signatures), and SLH-DSA (hash-based signatures). Even lattice hardness remains an unproven Conjecture, but no efficient quantum attack is known against it.