Kings and Queens of Cryptography

Crypto 1 of 2

The word "cryptography" means, literally, hidden writing. For most of history, the people doing the hiding weren't protecting bank logins. They were protecting battle plans, assassination plots, and their own necks. Get the writing right and you win an empire. Get it wrong and you lose your head. We'll get to a queen who lost hers.

You're using the tame modern version right now, mostly without noticing: the lock in your browser bar, the messages on your phone, your bank login, all scrambled into nonsense for anyone who intercepts them. We treat it like magic. It isn't. The core trick is two thousand years old, and you'll have it in about a minute.

Start with the king. Julius Caesar had a problem: a courier can be captured, and a captured battle plan is a lost battle. His fix was almost insultingly simple. Shift every letter forward a fixed number of spots in the alphabet. Shift by 3, and A becomes D, B becomes E, and Z loops back around to C. The shift is the key. Know it, and you can read anything. Miss it, and it's gibberish. It doesn't look like much. It also helped run the Roman military.

Caesar Cipher
+3

Shift past Z and you land back at A. Mathematicians call that working modulo 26 -- wrapping around a fixed size. Hold onto that word.

Plain text (input)
Cipher text (output)

Here's the trouble with a king's cipher: it only works on enemies who aren't paying attention. A simple shift has just 25 possibilities, so you could crack it by hand before your coffee got cold. But you wouldn't even bother. In English the most common letter is E, so the most common letter in the scrambled message is almost certainly E in disguise. Spot that, and the shift falls right out. What cost Caesar's enemies years now costs you a minute.

So cryptographers spent the next fifteen centuries hunting for something stronger, and in the 1500s, in the age of Elizabeth, they found a cipher fit for a queen. They were so sure of it they practically dared the world to break it. That kind of confidence, in cryptography, tends to age badly.

Vigenere Cipher (Elizabethan)

Same idea, but instead of one shift, type a cipher word. Each letter of your message shifts by the corresponding letter of the cipher -- cycling through it as you go. If your message is longer than the cipher, the shifts repeat from the beginning.

Cipher
Shift per cipher letter
Plain text (input)
Cipher text (output)
cipher hint: TerryPratchett

The Vigenere cipher swaps one shift for a whole keyword. Each letter of your message shifts by the matching letter of the keyword, cycling back to the start when it runs out. With the keyword "CIPHER," the first letter shifts by C, the next by I, then P, and so on. Now the same plaintext letter can come out as five different cipher letters depending on where it lands. Frequency analysis, the trick that cracked Caesar over coffee, simply collapses.

For nearly 300 years the queen's cipher held. The French called it le chiffre indechiffrable, the indecipherable cipher, which is roughly the cryptographic equivalent of christening your ship unsinkable. Diplomats trusted it. Spies trusted it. The Confederacy trusted it through the American Civil War, to notably poor effect.

And make no mistake about the stakes. This was an age when a broken code could cost you your head, and a queen found that out. Mary, Queen of Scots plotted against Elizabeth in cipher, certain her letters were safe. Elizabeth's codebreakers read every one, and in 1587 Mary went to the block for it. Secret writing was never a parlor game. It decided who kept their crown, and who kept their head.

And the indecipherable cipher fell too, not to a king or an army but to a commoner. In the 1800s Charles Babbage, the same man who designed the first mechanical computer, brought it down with a move that sounds too simple to work: look for repeated runs of letters in the ciphertext. If the same sequence shows up twice, the gap between them is probably a multiple of the keyword's length. Find the length, and the queen's unbreakable cipher falls apart into a stack of ordinary Caesar shifts. Dress a pattern up in silk. It still shows through.

But look at what the king and the queen had in common. Both ciphers need the sender and receiver to agree on a key in advance, which means the key has to travel, and a key that can be intercepted is a lock that can be picked. For four centuries that was the question nobody could answer: how do you share a secret with someone you've never met, over a line you know is being watched? In 1976, two mathematicians answered it, and the answer sounds like a magic trick. You can hand your lock to the entire world, enemies included, and it still only opens for you. That's the next page.

matthewkmeyer.com / projects