RSA Encryption Visualizer

Key Generation

Step 1: Select Two Prime Numbers

First, we need to select two distinct prime numbers (p and q).

How RSA Works

Key Generation

  1. Choose two distinct prime numbers p and q
  2. Compute n = p × q
  3. Compute φ(n) = (p-1)(q-1)
  4. Choose integer e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1
  5. Determine d as modular inverse of e modulo φ(n)

Encryption

c ≡ me mod n

Decryption

m ≡ cd mod n

Why It Works

Euler's theorem guarantees that for any message m:

mφ(n) ≡ 1 mod n

Since e × d ≡ 1 mod φ(n), we have:

(me)d ≡ me×d ≡ mkφ(n)+1 ≡ (mφ(n))k × m ≡ m mod n