All operations

Alphabetical substitution

Supply your own cipher alphabet and send every letter through it.

The general case

Give it twenty-six distinct letters. The first is what A becomes, the second what B becomes, and so on. Every other simple substitution cipher is this one wearing a particular alphabet: write the alphabet backwards and you have Atbash, which is the operation’s default, or rotate it three places and you have Caesar.

The plaintext loaded above is Edgar Allan Poe, writing in Graham’s Magazine in July 1841. He was wrong in general and right about this cipher.

The alphabet it runs under, frequncyabdghijklmopstvwxz, was built the traditional way: take a keyword, here FREQUENCY, drop its repeated letters, then follow with every letter it did not use. That gives a scrambled alphabet a person can rebuild from one memorized word.

Case survives, and anything that is not a letter passes through where it stands. The key field ignores case, spaces and punctuation, so a key can be typed in groups of five, and anything other than twenty-six distinct letters is refused.

The keyspace

Twenty-six letters can be rearranged 403,291,461,126,605,635,584,000,000 ways. That is roughly 88 bits, comfortably past the 56-bit key DES shipped with. No machine will ever try all of them.

The cipher is broken anyway, and has been for eleven hundred years.

Frequency analysis

The letter mapping never changes across the message, so every proportion in the plaintext arrives intact in the ciphertext under a different name. E accounts for around twelve percent of English letters and nothing else comes close, and the top six carry roughly half of all text. Count the ciphertext, match the shape, recover four or five letters, then read the half-finished words until the rest of the key falls out.

Al-Kindi set the technique down in Baghdad in the ninth century, in a manuscript on deciphering encrypted messages. It has been fatal to this cipher ever since, and no choice of alphabet helps, because the attack never touches the key.

Shannon’s 1949 paper on secrecy systems puts the unicity distance for English under simple substitution at about twenty-eight letters, the length past which exactly one key still fits. Below that a message does resist, which is why a six-letter substitution has no unique answer and why a solver working by hand wants a paragraph.

Where it still turns up

Puzzles, teaching, and keeping a value from someone who is not looking for it. It also works as one half of a product cipher, with a transposition afterwards to scatter the pairs frequency analysis feeds on.

Caesar and Atbash are both this cipher with the alphabet chosen for you. Vigenere answers the flaw by changing the mapping on every letter.