1001Ferramentas
🟦Security

Four-Square Cipher

Encrypts text two letters at a time using two keyword grids, with I and J sharing one cell and a trailing X padding an odd length. Encoding only.

Cifrado

Four-square: four grids to encipher in pairs

The four-square cipher, also from Delastelle, enciphers two letters at a time using four five-by-five grids. Two of them hold the alphabet in order and serve to locate the plaintext letters; the other two are scrambled by keywords and are where the ciphertext comes from. Enciphering in pairs is what sets it apart from letter-by-letter substitutions.

Enter the text and the two keys. Each pair of letters is located in the reference grids, and the result comes from the ciphering grids at the intersection of the matching rows and columns. As with the Polybius square, I and J share a cell, and an X is appended when the text has odd length, to close the final pair.

Enciphering in pairs is the real gain: frequency analysis of single letters stops working, because what matters is digram frequency — and that is far more spread out. Compared with Playfair, which uses two grids and has special rules for repeated letters and for pairs sharing a row, four-square is simpler to apply, since every pair falls into the general case.

Frequently asked questions

Do I need two different keys?
That is the normal use, and identical keys weaken the cipher because they create symmetry between the two ciphering grids. Pick two distinct words, preferably long ones, to better scramble the tail of the alphabet — which with a short key stays almost in order.
Why does an X appear at the end?
Because the cipher works in pairs and an odd-length text would leave the last letter alone. X is the traditional padding for being rare in running text. When deciphering, a lone X at the end is usually padding rather than part of the message.
Is it stronger than Playfair?
Slightly, for two reasons: it has none of the special rules that create recognisable patterns, and it uses two keys instead of one. Both remain vulnerable to digram analysis given enough text — a few hundred characters suffice for an experienced cryptanalyst.

Related Tools