How Goldwasser–Micali works
Shafi Goldwasser and Silvio Micali's system encrypts one bit at a time, so a message turns into a long list of big numbers. Each number hides a single 0 or 1 in whether it's a square modulo the secret primes.
Squares modulo a prime
Modulo a prime p, half the numbers are squares (quadratic residues) and half aren't. Anyone who knows p can tell which in one step, using Euler's criterion: a(p−1)/2 mod p is 1 for a square and p − 1 (that is, −1) for a non-square. Modulo n = p × q, telling squares from non-squares without knowing p and q is believed to be as hard as factoring.
Making the keys
- Pick secret primes p and q, and publish n = p × q.
- Publish a number x that is not a square modulo p and not a square modulo q. To an outsider it looks like it could be a square.
Locking and unlocking
- For each bit, pick a random y. Send y2 mod n for a 0, or y2 × x mod n for a 1.
- To decrypt each number, check whether it's a square modulo p: square means 0, non-square means 1.
- String the bits together and read them, usually 8 at a time as ASCII.
The whole thing with tiny numbers
What the puzzle gives you
A Goldwasser–Micali puzzle gives a public key (n, x) and a list of ciphertext numbers, one for each bit of the message.
Paste them all, in order. Separate them with spaces, commas, or line breaks. Each one is smaller than n, and there's one per bit, so a 3-letter message in 8-bit ASCII is 24 numbers.
Already know p and q?
If the puzzle hands you the private primes, fill them in and the worksheet uses them instead of factoring.
Split n into p × q
Knowing p is what lets you tell squares from non-squares.
Check x
For the system to work, x must be a non-square modulo both primes.
One bit per number
For each ciphertext number c, work out c(p−1)/2 mod p. If it's 1, c is a square and the bit is 0. If it's p − 1, the bit is 1.
Show every number
Read the bits
Group the bits into characters. 8 bits per character (ASCII) is the most common; the puzzle should say if it's different.