FundamentalsBeginner

RSA Encryption Visualizer

Type a message and watch RSA encrypt and decrypt it step by step. See modular exponentiation, key generation, and the square-and-multiply algorithm in action.

Interactive Demo
RSA Encryption
Step 01 — Foundation

Choose Prime Pair p, q

RSA begins with two prime numbers. Their product n = p × q is easy to compute but nearly impossible to factor in reverse — that asymmetry is the entire basis of RSA security.

Steps 02 – 05 — Key Generation

Computing Public & Private Keys

p (prime)
11
q (prime)
13
n = p × q
143
φ(n) = (p−1)(q−1)
120
e — public exp
7
d — private exp
103
Public Key: (e=7, n=143) — share freely
Private Key: (d=103, n=143) — guard carefully
Verify: e × d mod φ(n) = 1 ✓   gcd(e, φ(n)) = 1
Step 06 — Plaintext

Type Your Message

Each character is encoded as its ASCII value (0–127). That value must be less than n=143 for RSA to work correctly. Up to 8 characters for this demo.

5/8 charsASCII range: 32–126, must be < n=143
Step 07 — Encryption (Public Key)

Plaintext → Ciphertext

Formula: c = m^e mod n = m^7 mod 143  — click any character to trace the math
char
H
ascii
72
cipher
19
char
e
ascii
101
cipher
62
char
l
ascii
108
cipher
4
char
l
ascii
108
cipher
4
char
o
ascii
111
cipher
45
Ciphertext: [19, 62, 4, 4, 45]
Step 08 — Decryption (Private Key)

Ciphertext → Plaintext

Formula: m = c^d mod n = c^103 mod 143  — only the holder of d can decrypt
cipher
19
ascii
72
char
H
cipher
62
ascii
101
char
e
cipher
4
ascii
108
char
l
cipher
4
ascii
108
char
l
cipher
45
ascii
111
char
o
Decrypted ASCII: [72, 101, 108, 108, 111]
Plaintext: "Hello"
✓ Round-trip complete — decrypted matches original
The Math Behind It

Why RSA Works

Euler's theorem
m^φ(n) ≡ 1 (mod n) when gcd(m,n)=1. RSA exploits this so m^(e·d) ≡ m (mod n).
Key relationship
e·d ≡ 1 (mod φ(n)), so encrypting then decrypting returns the original value.
One-way trapdoor
Factoring n into p and q is computationally hard — making d impossible to find without knowing φ(n).
Real-world scale
Production RSA uses 2048–4096 bit primes. This demo uses tiny primes for visible arithmetic.
Real RSA uses primes with 617+ digits. This visualization uses small primes for educational transparency.

Want to learn more?

Read our complete guide on how RSA encryption works