Xerobit

Polybius Square Cipher: Encode and Decode Text

The Polybius square converts each letter into a pair of row and column digits using a 5 by 5 grid where I and J share one cell. Enter your text below to encode it into numbers or decode digit pairs back into letters. You can use the standard alphabet or supply a keyword to rearrange the grid. Everything runs in your browser and nothing is uploaded.

Result

23 15 31 31 34
12345
1ABCDE
2FGHI/JK
3LMNOP
4QRSTU
5VWXYZ

By · Published · How we build and test tools

How to use the polybius square

  1. Type or paste your message into the Text field.
  2. Choose Encode to convert letters into digit pairs, or Decode to convert digit pairs back into letters.
  3. Optionally enter a Keyword to generate a scrambled grid instead of the standard alphabet order.
  4. Read the encoded output or decoded message, along with the generated Polybius square table.

How the Polybius Square Works

The Polybius square is a substitution method that replaces each letter with two digits representing its row and column in a 5 by 5 grid. Because the Latin alphabet has 26 letters and the grid holds only 25 cells, the letters I and J are combined into a single cell.

To encode the word HELLO using the standard grid, look up each letter:

  • H is in row 2, column 3, giving 23.
  • E is in row 1, column 5, giving 15.
  • L is in row 3, column 1, giving 31.
  • L again gives 31.
  • O is in row 3, column 4, giving 34.

The final encoded string is 23 15 31 31 34. Decoding reverses this process by reading each pair of digits as a row and column coordinate and looking up the corresponding letter in the same grid.

Standard Grid Reference

The default Polybius square uses the alphabet in order, merging I and J into one cell. Here is the standard layout used when no keyword is provided:

12345
1ABCDE
2FGHI/JK
3LMNOP
4QRSTU
5VWXYZ

When you supply a keyword, the unique letters of that keyword fill the grid first from left to right, top to bottom. The remaining letters of the alphabet follow in their normal order, skipping any already placed. For example, the keyword CIPHER produces the sequence C, I, P, H, E, R, A, B, D, F, G, K, L, M, N, O, Q, S, T, U, V, W, X, Y, Z.

Worked Example with a Keyword

Let us encode the word ATTACK using the keyword CIPHER. First, build the grid by writing the unique letters of CIPHER, then the rest of the alphabet:

12345
1CIPHE
2RABDF
3GKLMN
4OQSTU
5VWXYZ

Now look up each letter of ATTACK in this custom grid:

  • A is at row 2, column 2: 22
  • T is at row 4, column 4: 44
  • T is at row 4, column 4: 44
  • A is at row 2, column 2: 22
  • C is at row 1, column 1: 11
  • K is at row 3, column 2: 32

The encoded result is 22 44 44 22 11 32. Both sender and receiver must agree on the exact keyword to build identical grids.

Historical Background

The Greek historian Polybius invented this grid around 150 BC as a way to signal letters using torches. By holding a specific number of torches on the left for the row and on the right for the column, soldiers could transmit messages across long distances without shouting. This makes the Polybius square one of the oldest known cryptographic tools.

In modern times, the same principle appears in the tap code used by prisoners of war, where taps replace torches. It also forms the mathematical foundation for more complex systems like the Playfair cipher, which encrypts pairs of letters using a similar 5 by 5 grid rather than converting them to digits.

Common Mistakes and Edge Cases

When decoding, the input must contain an even number of valid digits between 1 and 5. If you provide an odd number of digits, or a digit like 6 or 0, the polybius cipher decoder cannot map it to a grid cell and will return an error. Spaces between pairs are ignored during decoding, so both 2315 and 23 15 decode identically. A slash is read as a word break, and punctuation is kept as it is.

Another common issue involves the letter J. Because I and J share a cell, encoding a message with J produces the same digits as I. When decoding, the tool always outputs I for that cell. If your original message contained a J, the recipient will read it as an I. This is an inherent limitation of the 5 by 5 grid design.

Unlike shifting methods such as the Caesar cipher translator or the Vigenere cipher, the Polybius square cipher does not change the frequency distribution of the underlying letters. It merely translates them into a different format. Frequency analysis on the resulting digit pairs can still reveal patterns if the message is long enough.

Worked examples

ExampleInputResult
Encode HELLOText: HELLO; Direction: encode23 15 31 31 34
Decode 23 15 31 31 34Text: 23 15 31 31 34; Direction: decodeHELLO
Encode with keyword CIPHERText: ATTACK; Direction: encode; Keyword (optional): CIPHER22 44 44 22 11 32

FAQ

What is a Polybius square?

A Polybius square is a 5 by 5 grid that maps each letter of the alphabet to a pair of coordinates representing its row and column. The letters I and J share a single cell to fit all 26 letters into 25 spaces.

How do I decode a Polybius cipher?

Split the encoded message into pairs of digits. Use the first digit as the row number and the second as the column number to find the matching letter in the grid. Both parties must use the same keyword if one was applied.

Why are I and J combined in the grid?

The grid has exactly 25 cells but the English alphabet has 26 letters. Combining I and J into one cell is the traditional solution because they sound similar and context usually clarifies the intended letter.

Does the keyword make the cipher secure?

A keyword scrambles the grid so an attacker cannot use the standard alphabet layout, but the cipher remains a simple substitution. It is useful for puzzles and education but not for protecting sensitive data.

Can I use numbers or punctuation in my message?

Punctuation is passed through unchanged, and a space between words is written as a slash so it is not confused with the gap between letters. Digits cannot be encoded because the output itself is made of digits, so spell numbers out as words.

Is this tool safe to use for private messages?

The tool runs entirely in your browser and nothing is uploaded to any server. However, the Polybius square cipher itself is a classical method that is easy to break, so it should only be used for puzzles or educational purposes.