RSA Encryption
RSA multiplies two primes to build a public modulus, then uses modular exponentiation to encrypt and decrypt. Change the toy primes and message to see every step.
The public key exposes n and e; the private exponent d is derived from φ(n), which requires factoring n. Encryption raises the message to e, and decryption raises the ciphertext to d. These are toy primes — real RSA uses enormous keys and padding.
What you are seeing
Choose primes p and q. The public modulus is n = pq and φ(n) = (p − 1)(q − 1).
Pick e coprime to φ(n). The private exponent d satisfies e d ≡ 1 (mod φ(n)).
Encrypt with c = mᵉ mod n and decrypt with m = cᵈ mod n. The public sees n and e but not the factorization.
Why it matters
RSA secures websites, software updates, and digital signatures. It is a direct application of primes, modular arithmetic, and the difficulty of factoring large numbers.
Complexity & details
Modular exponentiation is O(log e) multiplications. Factoring n is believed to be hard for large semiprimes, which is what keeps RSA secure.
Frequently asked questions
Why can’t anyone decrypt with the public key?+
The public key gives n and e, but recovering d requires φ(n), which requires factoring n. For large primes, factoring is infeasible.
Is this demo secure?+
No. It uses tiny primes so every step is visible. Real RSA uses keys hundreds or thousands of bits long and secure padding.