The Four-square cipher, invented by Félix Delastelle in the late 1800s, is a digraph substitution cipher that encrypts pairs of letters using four 5×5 grids. Two of the grids hold keyword alphabets and two hold the plain alphabet, arranged in a 2×2 block. Using two separate keys makes it noticeably stronger than the single-square Playfair cipher. This tool builds the squares and applies the real rules in your browser.
How it works
Arrange four 5×5 squares in a block. The top-left and bottom-right squares hold the plain alphabet (I and J merged). The top-right square is keyed with keyword 1 and the bottom-left square is keyed with keyword 2.
Split the plaintext into pairs, padding a final lone letter with X. For each pair, find the first letter in the top-left plain square and the second letter in the bottom-right plain square. The two ciphertext letters are taken from the opposite corners of the rectangle they form: the first comes from the top-right keyed square at (row of letter 1, column of letter 2), and the second from the bottom-left keyed square at (row of letter 2, column of letter 1).
Decryption simply reverses the lookup: locate the ciphertext letters in the two keyed squares and read the plaintext pair from the corresponding cells of the two plain squares.
Example
With keyword 1 EXAMPLE and keyword 2 KEYWORD, the plaintext pair HE encrypts to FY: H sits at row 1, column 2 of the plain square and E at row 0, column 4, so the cipher letters are the top-right square’s cell (1, 4) and the bottom-left square’s cell (0, 2).
Notes
Because each square can be keyed independently, the Four-square cipher does not suffer Playfair’s reversible-pair weakness, and identical letters in a pair encrypt cleanly without an inserted X. Decrypted text may still contain a trailing padding X or an I that should be read as J.