The keyword Polybius square is a classic cipher that maps each letter to a pair of coordinates in a 5×5 grid. Adding a keyword scrambles the grid so the coordinates are not the same as a plain alphabetical Polybius square, making it a popular building block in puzzle hunts and historical cryptography. This tool builds the keyed grid and encodes text locally in your browser.
Background
The Polybius square dates to ancient Greece, described by the historian Polybius as a signalling system using torches. In its basic form the alphabet fills a 5×5 grid in order and each letter becomes a row-column number pair. The keyword variant — popularised in 19th- and 20th-century cipher manuals — scrambles the grid so that the coordinates reveal nothing about the letter order to someone who does not know the keyword.
How it works
First the keyword’s letters are written into the grid left-to-right, top-to-bottom, skipping any letter that already appeared. Then the remaining letters of the alphabet (in order) fill the leftover cells. Because the square has only 25 cells, J is merged with I.
For the keyword GERA, the grid begins G E R A and then continues with B C D F H...:
1 2 3 4 5
1 G E R A B
2 C D F H I
3 K L M N O
4 P Q S T U
5 V W X Y Z
To encode a letter you read its row then its column. A sits at row 1, column 4, so it becomes 14. The full message is a stream of two-digit pairs.
Worked example
With the keyword GERA, the word HIDE encodes as:
- H → row 2, col 4 →
24 - I → row 2, col 5 →
25 - D → row 2, col 2 →
22 - E → row 1, col 2 →
12
So HIDE becomes 24 25 22 12. To decode, look up each two-digit pair in the same keyed grid and read the letter at that position.
Decoding and reversibility
Decoding is the exact reverse: split the ciphertext into two-digit groups, find each row-column position in the keyword-seeded grid, and read the letter. Because J maps to I during encoding, any decoded I should be read as I or J based on context.
Practical notes for puzzle setters
- Choose a keyword without repeated letters — duplicates are silently dropped, so
BANANAeffectively becomesBAN, producing a very short initial fill that looks thin to solvers. - Longer keywords increase the scramble. A one-letter keyword barely shifts the grid; a ten-letter keyword mixes the first two rows almost completely.
- The grid is its own key. Displaying the filled grid alongside a ciphertext is a common puzzle variant where solvers must build the grid themselves from a given keyword.
- Frequency analysis still works. The Polybius square is a monoalphabetic substitution — each letter always produces the same coordinate pair — so letter frequency in the ciphertext reveals the underlying English frequency pattern. It is designed for puzzles and teaching, not security.
Everything runs in your browser — no data is uploaded.