Paul's Crosswords Blog

Playfair code gadget

The Playfair cipher is a perennial feature of thematic crosswords, so I’ve put together a little gadget to speed up encoding and decoding using it.

What’s the Playfair cipher?

Unlike simple substitution ciphers, which encode one letter at a time according to a certain rule, a Playfair cipher encodes pairs of letters. So a message to be encoded is broken up into letter pairs

SO ME TH IN GL IK ET HI SM AY BE

and each pair is encoded using a code square, which looks like this:

You’ll notice that the codeword consists of a keyword or phrase, followed by the rest of the alphabet in order. Since nobody had the foresight to arrange for the alphabet to have a number of letters conducive to being arranged in a grid, we treat the letters I and J as if they were the same. To encode a pair of letters you find them in the grid, and then imagine them as the corners of a rectangle. Each letter encodes to the letter at the other corner on the same row. So our first pair SO encodes as MC. The nice thing about this is that to decode a letter pair, you do exactly the same thing.

Slightly less elegant is the case where the two letters are in the same row or column. In this case to the letters are simply shifted to the right one place (of they’re in the same row) or down one place (if they’re in the same column). Letters shifted off the end of a row or column go back to the start. So for instance our pair GL encodes as HF. The whole message encodes as

MCPAVFGQHFGYAVILMNKWDY

There are a few niggles that actual spies probably had to deal with when using Playfair, but the artificial world of a crossword tends to be designed so they don’t come up:

  • If the message has an odd number of letters: just stick an X on the end.
  • If the code word or phrase has a letter in it more than once: all occurences after the first are ignored. So SUPER SECRET KEYWORD would be put in the grid as SUPERCTKYWOD.
  • If one of the letter pairs is the same letter twice: I think you’re supposed to put an X between them. This will defnitely never come up in a crossword.

Playfair in crosswords

A typical Playfair-based crossword will require the solver to encode some answers before entering them in the grid, using an unknown keyphrase. While proper codebreakers would have to do fancy frequency analysis on pairs of letter in English to break a Playfair cipher, for crossword solvers what this means is using the letters from crossing answers to make deductions about what the code-square must look like, until you can make a guess at the keyphrase. (For example, if you can see from the crossing answers that AB has to encode as BC, you know that ABC occur together in a row or column, since corners-of-rectangle decoding can never give you the same letter in the encoded and decoded forms of a pair.) The setter ought to have arranged it so there’ll be just enough information to make this possible – and hopefully the clues that lead to the answers to be encoded will have been made not-too-tricky, as you effectively get no help with them from the crossing letters. The keyphrase will normally be related to the theme of the puzzle, or at least be a satisfyingly long word with no repeated letters. Azed regularly sets Playfair crosswords for his monthly competition puzzles, in which four answers have to be encoded in the grid, and competitors write a clue for the keyword.

Playfair also makes semi-frequent appearances in the Listener, including one puzzle about how dispiriting it can be to discover that week’s crossword includes a Playfair element. (That particular puzzle incorporated a code-square in the grid, and gave full instructions on how the code works in the instructions, but never actually required any encoding or decoding).

The best use of the code in a puzzle was Listener No 4147, OZ and WR by Theod.