The Black Chamber RU

Tools · Classical ciphers

Playfair cipher

Playfair: the 5×5 key square and digraph encryption with each rule highlighted.

Runs in your browser. Your text goes nowhere.

How to use it

Type a key and a text. The key becomes a 5×5 square: first the key's letters without repeats, then the rest of the alphabet. There are 26 letters and only 25 cells, so I and J share one. The result appears at once, in pairs. Click any pair next to the square, or step through them with the arrows, and the square lights up the original letters (black), the letters they become (red), and the row, column or rectangle the rule works on.

Digits, punctuation and non-Latin letters are skipped.

Three rules

Before encrypting, the text is cut into pairs of letters. J becomes I. If a pair would hold two identical letters, an X goes between them: “balloon” turns into BA LX LO ON. If a single letter is left at the end, it gets an X. Then each pair is encrypted by a rule:

  • same row: replace each letter with its neighbour to the right (from the last column round to the first);
  • same column: replace each with the neighbour below (from the bottom row round to the top);
  • different rows and columns: the letters are corners of a rectangle; replace each with the corner in its own row.

Decryption is the same in reverse: neighbours to the left and above, the rectangle as it is. The stray Xs are removed afterwards by sense.

History and strength

The cipher was invented in 1854 by Charles Wheatstone and promoted by his friend Lord Lyon Playfair, which is how it got its name. The British army used it as a field cipher in the Boer War and the First World War. Its big idea is to encrypt pairs instead of single letters: there are about 600 pairs, their frequencies are spread more evenly, and the simple counting from the substitution lesson works less well. A long message still falls to the common bigrams, TH, HE, IN, ER, because Playfair is only a substitution of letter pairs and shares its weaknesses.

FAQ

Why is there no J in the square?

It shares a cell with I, since a 5×5 square holds only 25 letters. When you decrypt, an I may stand for J; the sense tells you which.

Why do I see extra Xs after decrypting?

They were added before encryption to split doubled letters and to complete the last pair. Just drop them.

Is it safe to paste my text here?

Yes. Everything runs in your browser and nothing is sent to a server.