Why a Scrambled Alphabet Is Not Safe
At the end you were told how to make a harder code: instead of shifting every letter along by three, scramble the whole alphabet. A becomes Q, B becomes F, C becomes M, in no order at all.
That really is harder. It is enormously harder in the one way people usually measure, and it is worth seeing just how enormously before finding out that it does not help.
Count the keys
With a shift code, the key is a single number. Shift by 1, or 2, or up to 25 — and shifting by 26 puts everything back where it started. Twenty-five keys. A patient person tries them all in a few minutes.
Now count the scrambled ones. Pick any of the 26 letters to stand for A. That leaves 25 to choose from for B, then 24 for C, and so on down to the last letter, which has no choice left at all.
Multiply all of that together and you get a number twenty-seven digits long.
Here is what a number that size means. Suppose you could test a million keys every second — not a person, a machine, a million every second without stopping. Run it from the day you were born to the day you are very old, and you would not have got through a billionth of them.
So it is safe. That is the obvious conclusion and it is wrong, and the reason it is wrong is the best thing on this page.
Nobody is going to try the keys
A scrambled alphabet is not broken by hunting through keys. It is broken by counting letters, and the counting takes an afternoon.
Here is the leak. Scrambling changes which letter is which. It does not change how often each one is used.
In English writing, the letter E turns up more than any other, and not by a little. Every message you have ever written is full of them. When you scramble the alphabet, every one of those Es becomes some other letter — but they all become the same other letter, and it appears in the coded message exactly as often as the E did in yours.
So the commonest letter in the code is almost certainly E. You did not try a key. You just counted, and the code told you.
Watch one come apart
Somebody hands you this and no key at all.
VQQZ VQ KQJQ PKQX ZKQ DQCC JFXNY
Follow it letter by letter. Nothing here is a guess at the key.
- Count. Q appears eight times, and nothing else comes close — the next best manages three. In a message this short that is a very loud signal.
- Read every Q as E. Suddenly you can see word shapes: a four-letter word starting with two Es in the middle, a four-letter word that is E-something-E-something.
- Look at ZKQ. Three letters, ending in E, standing on its own. The commonest three-letter word in English is THE, so Z is T and K is H. Two more letters, for free, and you have still not tried a key.
- Now KQJQ reads HE_E, which can only really be HERE, so J is R. VQQZ reads _EET and VQ reads _E, and MEET and ME fit both at once, so V is M. PKQX is _HE_ — WHEN. Every letter you win hands you the next.
- DQCC is _E__ with a doubled letter at the end: BELL. JFXNY starts R and has an N: RINGS. The message is MEET ME HERE WHEN THE BELL RINGS, and the key was never needed.
Notice what did the work. The doubled letters stayed doubled. The short words stayed short. The gaps between words stayed where they were. None of that is hidden by swapping letter names, and all of it is a way in.
The thing worth keeping
A code is not strong because it has a lot of keys.
The shift code and the scrambled code have wildly different numbers of keys — twenty-five against a twenty-seven-digit number — and they lose to the same attack, because they leak the same thing. In both, one letter of your message always turns into the same letter of the code. Every time. That single habit is what the counting feeds on, and no amount of extra keys removes it.
Ask a different question about a code, and it is a much better question: does the coded message give anything away about the real one? If the answer is yes, the number of keys is decoration.
Two codes are being compared. Why does the one with a twenty-seven-digit number of keys fall just as fast as the one with twenty-five?
- Because both are very old codes
- Because in both, one letter always becomes the same letter, so the letter counts survive and give the message away
- Because computers can now try every key in either code
- Because both were invented before people knew about letter counting
Make yours actually harder
The weakness is that one letter always becomes the same letter. So change the key as you go.
Agree a short word with your friend — say CAT — and write it over and over above your message. Shift each letter by a different amount depending on the letter above it: C shifts by 3, A by 1, T by 20. Now the Es in your message stop all turning into the same letter, and the tall bar in the counting flattens right out.
That one change is the difference between a code somebody unpicks over a wet afternoon and a code that held up for centuries.
One last thing to try on a friend
Give somebody a scrambled-alphabet message and tell them, honestly, how many keys there are. Watch them decide it is hopeless.
Then hand them a pencil and tell them to count the letters instead.