Computer Science · Simulator 057
Build a tiny RSA key pair from two small primes, then encrypt a message with the public key and decrypt it with the private key, one modular calculation at a time. Try to break the key by factoring n, and see why real keys use primes hundreds of digits long.
Key generation:
Encrypt: c = mᵉ mod n. Decrypt: m = cᵈ mod n. This works because of Euler's theorem. Sign with d and anyone can verify with e.
The public key is (n, e). Knowing p and q gives φ and therefore d, so security rests on factoring n being hard. For the toy sizes here it takes microseconds; for 2048-bit keys, no known classical method finishes in any practical time.
Educational only. Tiny keys, no padding, and character-by-character encryption are completely insecure. Never use this for real secrets. Real RSA uses padding schemes (OAEP, PSS) and 2048+ bit keys.
With n = 3233 and e = 17, why does encrypting each letter separately leak information even though the key is “correct”?
The same letter always gives the same ciphertext number, so frequency analysis works exactly as for a simple substitution cipher. Repeated letters are visible in the ciphertext readout. Real RSA adds random padding so equal messages encrypt differently, and it usually encrypts only a random symmetric key.