RSA art
Modular multiplication drawn as glowing string art, and the same maths turned into RSA encryption: keys, a message, the square-and-multiply trick and an eavesdropper trying to break it.
Toy only. Never use this for real security: these keys are tiny and there is no padding.
Square and multiply
The numbers
Key generation
Eavesdropper
Eve sees the public key (n, e). To read anything she has to split n into p × q. Here she tries every odd divisor in turn, the brute-force way. Toy only, never use for real security.
Challenge: read the hidden message
An intercepted message, encrypted with the public key below. Find the private exponent d and type it in. Hint: factor n with the eavesdropper, set p and q in the controls above, and the key cards will show d.
Diffie-Hellman: the other door
The same modular powers do a second job. RSA locks with a public key; Diffie-Hellman lets two strangers agree a secret key in public. Here it runs in a group made from your key's own primes. Open the full Diffie-Hellman page for the paint-mixing version, step-by-step playback and the race. Toy only.
Gallery of patterns found
How it works
Put n points on a circle and join each point i to (i × k) mod n. With k = 2 a cardioid appears, with k = 3 a nephroid, and as k slides through fractions the lines sweep between them. Counting where the lines go, the cycles and the repeats, is modular arithmetic made visible.
RSA uses powers instead of multiples. Pick two primes p and q and publish n = p × q and an exponent e. Anyone can encrypt a number m as c = me mod n, but only someone who knows d can undo it with m = cd mod n. Choosing d so that e × d leaves remainder 1 when divided by φ(n) = (p - 1)(q - 1) makes the two powers cancel, by Euler's theorem.
This is a one-way function with a trapdoor. Multiplying p and q takes a moment; getting them back from n alone is the hard direction, and finding d needs φ(n), which needs p and q. The public key locks, the private key unlocks. Square and multiply makes the big powers cheap: one squaring per bit of the exponent, plus a multiply for each 1 bit.
the same circle that draws a cardioid hides a lock: decryption draws exactly the same chords as encryption, walked the other way.
Toy only. Real RSA uses primes hundreds of digits long, random padding such as OAEP, and audited libraries. Never use this page to protect anything.