Skip to main content
Basic Classic Symmetric Beginner

The Polybius Square Cipher

Learn about the Polybius square, the ancient Greek cipher that turns every letter into a pair of coordinates. It became the foundation for tap codes, telegraph ciphers, and the ADFGVX cipher.

PL
Pashalis Laoutaris
August 21, 2026
11 min read

Interactive Polybius Square Visualizer

🔐 Polybius Square Visualizer

5
Enter text and click a button to start!
HELLO

The Polybius Square: Turning Letters Into Coordinates

Introduction

Every cipher covered so far in this series outputs letters: a different letter, in a different order, but still letters. The Polybius square, devised by the Greek historian Polybius around the 2nd century BCE, does something different: it converts each letter into a pair of numbers, its row and column position in a 5×5 grid. Originally designed as a long-distance signaling system (using torches to transmit numbers rather than letters), its coordinate-based idea turned out to be remarkably durable. It’s the direct ancestor of tap codes, several telegraph-era ciphers, and the more sophisticated ADFGVX cipher used in the First World War.

Table of Contents

How the Polybius Square Works

The Polybius square arranges the alphabet into a 5×5 grid, with rows and columns numbered 1 through 5:

    1  2  3  4  5
1   A  B  C  D  E
2   F  G  H  I/J K
3   L  M  N  O  P
4   Q  R  S  T  U
5   V  W  X  Y  Z

To encrypt, each letter is replaced by its row number followed by its column number. H sits in row 2, column 3, so it becomes “23”. The result is a stream of digit pairs instead of letters. Decryption simply reverses each pair back to the letter at that row and column. As with every cipher in this series, spaces and punctuation are conventionally stripped from the message before encoding. Only letters get converted to coordinates. The coordinate pairs themselves are conventionally written with a space between each pair (as throughout this article), purely for readability. Since every pair is exactly two digits, the digits could equally well be run together with no separator at all and still be unambiguously split back into pairs during decryption.

Interactive Visualizer

Try it above. Enter text to see each letter’s grid position highlighted as it’s converted to coordinates, or enter space-separated coordinate pairs (like “23 15 31 31 34”) and click Decrypt to convert them back.

Handling 26 Letters in 25 Cells

A 5×5 grid has exactly 25 cells, but the Latin alphabet has 26 letters, one too many. The standard solution is to merge I and J into a single cell, since they’re historically related letters and rarely both appear in ways that create genuine ambiguity in practice. When decrypting, “I” is used as the default recovered letter for that cell; context usually makes it obvious when “J” was actually intended. Merging I/J is the most common convention (and the one this article and visualizer use throughout), but it isn’t the only one seen historically. Some variants instead drop a rarer letter entirely, such as Q, when the plaintext alphabet or language doesn’t need it. A completely different solution to the same 25-cell limit is to simply use a larger grid. The ADFGVX cipher covered later in this series expands to a 6×6, 36-cell grid, specifically so it can fit the full alphabet and the ten digits without merging anything.

A Worked Example

Using the standard (unkeyed) grid shown above, encrypt “HELLO”. Marking each letter’s cell with square brackets makes the five lookups easy to verify against the grid directly:

    1  2  3  4  5
1   A  B  C  D [E]
2   F  G [H] I/J K
3  [L] M  N [O] P
4   Q  R  S  T  U
5   V  W  X  Y  Z
  • H: row 2, column 3 → “23”
  • E: row 1, column 5 → “15”
  • L: row 3, column 1 → “31”
  • L: row 3, column 1 → “31”
  • O: row 3, column 4 → “34”

“HELLO” → “23 15 31 31 34”

Decryption reverses each pair: “23” → row 2, column 3 → H; “15” → row 1, column 5 → E; and so on, recovering “HELLO” exactly.

Keying the Square

Like the monoalphabetic substitution cipher, the Polybius square’s letter arrangement doesn’t have to follow plain alphabetical order. A keyword can be used to scramble the grid the same way it scrambles a substitution cipher’s alphabet: write the keyword’s unique letters first, then fill in the remaining unused letters in order. This turns the basic Polybius square from a simple, fixed encoding scheme into a genuine (if still weak) cipher with a real key. The visualizer above supports this with its optional keyword field.

Pros and Cons Analysis

Advantages Disadvantages
Simple, Systematic Encoding: Trivial to perform by hand or transmit as pure numbers No Real Security on Its Own: Without a keyword, it’s a fixed, publicly-known mapping, pure obscurity, not encryption
Reduces the Alphabet to Two Digits: A natural fit for signaling systems (torches, taps, flags) limited to a small number of distinct signals Still a Monoalphabetic Substitution: Even with a keyword, each letter always maps to the same coordinate pair, so frequency analysis on the digit pairs works exactly as it does against any substitution cipher
Historically Foundational: Its coordinate-pair idea underlies several later, genuinely stronger ciphers I/J Ambiguity: Merging two letters into one cell introduces minor but real decoding ambiguity
Building Block for Fractionation: Splitting a letter into two independent coordinates (its row and its column) enables further scrambling techniques not possible with plain single-letter substitution Doubles the Ciphertext Length: Every letter becomes two digits, which is inefficient compared to a one-letter-to-one-letter substitution

Cryptanalysis and Breaking the Polybius Square

An unkeyed Polybius square provides no security whatsoever. The grid layout is public knowledge, so anyone can decode it instantly, identically to reading Morse code. A keyed Polybius square is a genuine substitution cipher in disguise. Each letter always converts to the same fixed coordinate pair, so standard frequency analysis applies directly to the digit-pair frequencies, exactly as it would to ciphertext letters in a monoalphabetic substitution cipher. The most common digit pair in a long enough ciphertext is very likely the encoding of E, and so on. The underlying cryptanalysis technique doesn’t care whether the “letters” being counted are actually digit pairs.

The Polybius Square’s Real Legacy

The Polybius square’s lasting importance isn’t as a cipher in its own right. It’s as a building block. Its core idea, representing a letter as two independent coordinates rather than a single symbol, is called fractionation, and it enabled cryptographic techniques that plain substitution ciphers can’t achieve:

  • Tap codes: Prisoners of war (notably in the Vietnam War) used Polybius-square-based tap codes to communicate secretly by tapping row and column numbers through prison walls.
  • The ADFGVX cipher: A German WWI-era field cipher that used a 6×6 Polybius-style grid (to accommodate digits as well as letters) combined with a columnar transposition step. It exploited exactly the fractionation idea to resist the frequency analysis that would otherwise break a straightforward substitution cipher.
  • Bifid and Trifid ciphers: These take fractionation further, splitting coordinates apart, interleaving them across multiple letters, and reassembling them in a different order. That deliberately breaks the one-to-one correspondence between plaintext letters and ciphertext coordinate pairs that makes basic Polybius vulnerable to frequency analysis. Concretely, Bifid writes out all the row numbers for a whole run of letters first, then all the column numbers, before re-pairing them two at a time. So a ciphertext pair can end up combining, say, one letter’s row with a completely different letter’s column, rather than always combining a single letter’s own row and column together the way basic Polybius always does.

Modern Relevance

The Polybius square itself secures nothing today, but its influence is genuinely still felt:

  • As the conceptual root of fractionation-based ciphers, a technique that meaningfully improved on plain substitution before modern cryptography existed.
  • In signaling and coding systems beyond cryptography entirely: its row/column structure is a natural fit anywhere symbols need to be reduced to a small, fixed set of distinguishable signals.
  • As a teaching bridge between simple substitution ciphers and the more resistant combined techniques (like ADFGVX) that followed historically.

Python Implementation

Building the grid (optionally from a keyword) and converting letters to coordinate pairs are the only two operations this cipher needs:

ALPHABET = 'ABCDEFGHIKLMNOPQRSTUVWXYZ'  # 25 letters, I/J share a cell

def generate_square(key=""):
    key = key.upper().replace('J', 'I')
    key = ''.join(c for c in key if c.isalpha())
    square = []
    seen = set()
    for char in key + ALPHABET:
        if char not in seen:
            seen.add(char)
            square.append(char)
    return square

def polybius_encrypt(text, square):
    text = text.upper().replace('J', 'I')
    text = ''.join(c for c in text if c.isalpha())
    pairs = []
    for char in text:
        row, col = divmod(square.index(char), 5)
        pairs.append(f"{row + 1}{col + 1}")
    return ' '.join(pairs)

def polybius_decrypt(ciphertext, square):
    digits = ciphertext.replace(' ', '')
    result = ''
    for i in range(0, len(digits), 2):
        row = int(digits[i]) - 1
        col = int(digits[i + 1]) - 1
        result += square[row * 5 + col]
    return result

if __name__ == "__main__":
    square = generate_square()  # unkeyed, standard A-Z grid
    plaintext = "HELLO"

    ciphertext = polybius_encrypt(plaintext, square)
    recovered = polybius_decrypt(ciphertext, square)

    print(f"Plaintext:  {plaintext}")
    print(f"Ciphertext: {ciphertext}")
    print(f"Recovered:  {recovered}")

This reproduces the worked example above exactly: HELLO23 15 31 31 34HELLO. Pass a keyword to generate_square, for example generate_square("CIPHER"), to get the keyed variant described above instead of the standard grid.

Limitations

This implementation is deliberately minimal:

  • No digit-vs-letter disambiguation. polybius_decrypt assumes its input is exactly coordinate pairs; it doesn’t validate that every character is a digit 1-5, so malformed input produces a confusing error rather than a clear one.
  • English letters only, formatting is lost. Spaces, punctuation, and case are stripped before encoding, and the I/J merge means a decrypted message can never distinguish which of the two was originally intended.
  • No support for the alternative “drop a letter” convention. As the Handling 26 Letters section above mentions, some historical variants drop a rarer letter like Q instead of merging I/J; this code only implements the I/J-merge convention.
  • Not intended for real security. As the Cryptanalysis section explains, this is still just a monoalphabetic substitution in disguise, keyed or not; digit-pair frequency analysis breaks it exactly as easily as letter-frequency analysis breaks plain substitution.

Conclusion

The Polybius square looks almost too simple to matter: just a grid, a row number, and a column number. But that simple idea, splitting a letter into two independent coordinates instead of one, opened the door to fractionation-based cryptographic techniques that plain substitution ciphers can’t touch. On its own it offers no real security: keyed or not, it’s still just a monoalphabetic substitution wearing a coordinate-pair disguise. But as a building block, it quietly underlies tap codes, telegraph ciphers, and the more resistant field ciphers, like ADFGVX, that followed it historically.

FAQ

What is the Polybius square cipher?

A cipher that arranges the alphabet into a 5×5 grid and represents each letter as a pair of numbers: its row and its column. Decryption reverses each pair back to the letter at that grid position.

How does the Polybius square handle 26 letters in a 25-cell grid?

I and J share a single cell, since a 5×5 grid has only 25 positions. Decryption conventionally recovers “I” for that cell; context usually resolves any ambiguity.

Is the Polybius square secure?

Not on its own. An unkeyed grid is public knowledge and offers no security at all; even a keyed grid is still just a monoalphabetic substitution cipher, fully vulnerable to frequency analysis applied to the digit-pair frequencies.

What does “fractionation” mean, and why does the Polybius square matter for it?

Fractionation means representing a symbol as multiple independent parts (here, a letter’s row and column) rather than as a single unit. This is the foundational idea behind stronger ciphers like ADFGVX, Bifid, and Trifid, which scramble those coordinate parts separately to resist frequency analysis in ways plain substitution can’t.

Where is the Polybius square used today?

It has no role in modern security, but its structure lives on in tap codes (notably used by prisoners of war for covert communication) and as the conceptual basis for several historically significant field ciphers.

References

  1. Wikipedia. “Polybius square.” Available at: https://en.wikipedia.org/wiki/Polybius_square

  2. Practical Cryptography. “Polybius Square Cipher.” Available at: http://practicalcryptography.com/ciphers/polybius-square-cipher/

  3. Singh, Simon. “The Code Book.” Doubleday, 1999.