Skip to content

Four-Square Cipher

Enter two keywords and a message to encode or decode it with Félix Delastelle's four-square cipher. The tool lays out the four 5 × 5 squares and marks the rectangle behind each pair of letters, so you can check the result by hand. Free, no sign-up, and nothing leaves your browser.

Mode

Its letters fill the square first, each used once; the rest of the alphabet follows in order. The two keywords may be the same, but then the cipher is weaker.

Fitting 26 letters into 25 cells

Along the rows is the usual way. The American Cryptogram Association's example writes it down the columns.

Only letters are enciphered. Spaces, digits and punctuation are dropped, and the result is in capitals.

An odd last letter is padded with X (Z if the letter is X); decoded text keeps that filler.

I and J share a cell, so every J comes back as I.

The four squares and the pairs

Encoding: find the first letter in the upper-left square and the second in the lower-right square. The first cipher letter is in the upper-right square, in the first letter's row and the second letter's column. The second cipher letter is in the lower-left square, in the second letter's row and the first letter's column.

Upper left — plain alphabet

ABCDE
FGHIK
LMNOP
QRSTU
VWXYZ

Upper right — keyed

EXAMP
LBCDF
GHIKN
OQRST
UVWYZ

Lower left — keyed

KEYWO
RDABC
FGHIL
MNPQS
TUVXZ

Lower right — plain alphabet

ABCDE
FGHIK
LMNOP
QRSTU
VWXYZ

Select a pair below. For encoding, its two plain letters (blue) sit in the two plain squares, and the cipher letters (amber) sit at the other corners of the rectangle they mark. Decoding runs the other way.

PairFirst letterSecond letterResult
H: row 2, column 3E: row 1, column 5FY
L: row 3, column 1P: row 3, column 5NF
M: row 3, column 2E: row 1, column 5NE
O: row 3, column 4B: row 1, column 2HW
I: row 2, column 4W: row 5, column 2BX
A: row 1, column 1N: row 3, column 3AF
K: row 2, column 5E: row 1, column 5FO
N: row 3, column 3O: row 3, column 4KH
B: row 1, column 2I: row 2, column 4MD
Y: row 5, column 4O: row 3, column 4YI
U: row 4, column 5A: row 1, column 1OO
R: row 4, column 2E: row 1, column 5TE
M: row 3, column 2Y: row 5, column 4KU
O: row 3, column 4N: row 3, column 3II
L: row 3, column 1Y: row 5, column 4KT
H: row 2, column 3O: row 3, column 4DH
P: row 3, column 5E: row 1, column 5NO

How to Use the Four-Square Cipher Tool

  1. 1. Enter two keywords. The first fills the upper-right square and the second the lower-left one. Only letters count, and each is used once before the rest of the alphabet follows.
  2. 2. Choose the square convention. Fit 26 letters into 25 cells by sharing a cell between I and J or by leaving out Q, and pick how the keyword is written in. Match whatever your puzzle or textbook used.
  3. 3. Type the message and choose Encode or Decode. Only letters are enciphered; spaces and punctuation are dropped. An odd last letter is padded with X.
  4. 4. Read the working. Select a pair in the table to light it up: the plain letters in the two plain squares and the cipher letters at the other corners of the rectangle.

How the Four-Square Cipher Works

The four-square cipher enciphers two letters at a time. It uses four 5 × 5 squares in a 2 × 2 block. The upper-left and lower-right squares hold the plain alphabet. The upper-right and lower-left squares are keyed: each begins with its own keyword and continues with the unused letters in order.

To encipher a pair, find the first letter in the upper-left square and the second in the lower-right square. They sit at opposite corners of an imaginary rectangle. The first cipher letter is in the upper-right square, in the row of the first letter and the column of the second. The second cipher letter is in the lower-left square, in the row of the second letter and the column of the first. To decipher, run the same rectangle backwards, starting from the keyed squares.

Worked Example

The American Cryptogram Association's description of the cipher uses the keywords GEOMETRY (upper right) and LOGARITHM (lower left), each written down the columns, with I and J sharing a cell. Choose those settings and encode COMEQUICKLYWENEEDHELPX. Rows and columns below are counted from 1.

PairFirst letter (upper left)Second letter (lower right)Cipher
COC: row 1, column 3O: row 3, column 4LE
MEM: row 3, column 2E: row 1, column 5WI
QUQ: row 4, column 1U: row 4, column 5XA

For CO, the first cipher letter is in the upper-right square at row 1, column 4 (L), and the second is in the lower-left square at row 3, column 3 (E). The whole message becomes LEWIXAFNEXCUDXUVDPGXHZ, the cipher text printed in the ACA's description. Notice that a pair always gives the same cipher pair, but no letter-by-letter pattern shows: the same plain letter becomes different letters depending on its partner.

Conventions that change the answer

Published examples do not all agree, which is why the tool makes them selectable. Wikipedia's example, with keywords EXAMPLE and KEYWORD written along the rows, turns HELPMEOBIWANKENOBI into FYGMKYHOBXMFKKKIMD only when Q is left out of the squares instead of merging I and J. With I and J merged, the same input gives a different answer, so always match the convention before you compare.

Where the Four-Square Cipher Comes From

The cipher is the work of Félix Delastelle (1840–1902), a French amateur cryptographer who also invented the bifid and trifid ciphers. He gathered his systems in the Traité élémentaire de cryptographie, which Gauthier-Villars published in Paris in 1902, a few months after his death. Four-square is a close cousin of Playfair, which enciphers pairs on a single square. It needs two keywords and four grids, so it is slower to prepare, and that extra work for a modest gain in strength is why Playfair became far more common.

How the Four-Square Cipher Is Broken

Four-square hides single-letter frequencies, because each letter depends on its partner. It does not hide pair frequencies: a given plain pair always produces the same cipher pair, so the common English pairs such as TH and HE leave repeating pairs in the cipher text. Given a few hundred letters, a computer can search the two keywords and score each guess by how English the decoded pairs look. With a known plain-text fragment the squares fall out almost by hand. Unlike Playfair, a reversed plain pair does not produce a reversed cipher pair when the two keywords differ, and doubled letters need no filler, which removes two of Playfair's giveaways.

A teaching cipher, not a secure one

Four-square is a good way to learn how digraph ciphers work. It cannot protect anything private against software.

Frequently Asked Questions

What is the four-square cipher?
The four-square cipher is a digraph substitution cipher that enciphers pairs of letters using four 5 × 5 squares: two plain alphabets and two keyed with different keywords. It was invented by the French cryptographer Félix Delastelle.
How do you decrypt a four-square cipher?
Split the cipher text into pairs. Find the first letter in the upper-right keyed square and the second in the lower-left keyed square. The first plain letter is in the upper-left square at the first letter's row and the second letter's column; the second plain letter is in the lower-right square at the second letter's row and the first letter's column.
How is the four-square cipher different from Playfair?
Playfair uses one key square and moves letters along rows or columns. Four-square uses four squares and always applies the rectangle rule. It needs no filler between doubled letters, and a reversed plain pair does not give a reversed cipher pair, but it takes two keywords and more preparation.
Do the two keywords have to be different?
No, but using the same keyword for both keyed squares makes the cipher easier to attack. Two different keywords give a different arrangement in each keyed square, and the cipher is only as strong as that difference.
What happens to the letter J, and to Q?
A 5 × 5 square holds 25 letters, so one has to go. Either I and J share a cell, and every J is read as I, or Q is left out and removed from the message. Published examples use both conventions, so choose the one that matches yours.
Is the four-square cipher secure?
No. Because the same plain pair always gives the same cipher pair, digraph frequency analysis works, and a computer can recover both keywords from a few hundred letters. It is a historical cipher for learning and puzzles.

Related Tools

More in Codes & Ciphers

See all Codes & Ciphers