---
title: "Polybius square"
description: "Turn symbols into row and column digits. Choose a square that fits your puzzle."
canonical_url: "https://ciphers.agntn.dev/ciphers/polybius"
---
# Polybius square

> Turn symbols into row and column digits. Choose a square that fits your puzzle.

<cipher-facts name="polybius">



</cipher-facts>

Polybius gives each symbol a row and column. Write both numbers, and you've got coordinates. It's a nice way to turn letters into digits.

```ts
const polybius = create("polybius");

polybius.encode("HELLO").text; // "23 15 31 31 34"
polybius.decode("23 15 31 31 34").text; // "HELLO"
```

## The classic 5×5 square

The default square holds A to Z. I and J share a cell. Each coordinate uses digits from 1 to 5. Pairs come out separated by spaces.

```ts
const polybius = create("polybius");

polybius.encode("JULIUS").text; // "24 45 31 24 45 43"
```

J encodes as I. Everything that isn't a letter gets dropped during encoding.

Want a keyed square? Pass a `key`. Its letters go first, without duplicates. The remaining alphabet follows.

```ts
const polybius = create("polybius");

polybius.encode("HELLO", { key: "KEYWORD" }).text; // "33 12 35 35 15"
```

[Playfair](https://ciphers.agntn.dev/ciphers/playfair), [Bifid](https://ciphers.agntn.dev/ciphers/bifid) and [Nihilist](https://ciphers.agntn.dev/ciphers/nihilist) build the same keyed square. [Tap code](https://ciphers.agntn.dev/ciphers/tap-code) shares C and K instead. Bifid and [ADFGVX](https://ciphers.agntn.dev/ciphers/adfgvx) build on coordinates.

## A 6×6 Polybius square with digits

Pass `alphabet` to choose every cell. Symbols fill the square row by row. The alphabet's length determines its side.

A 6×6 square fits 26 letters and 10 digits. No leftovers. J gets its own cell.

```ts
const polybius = create("polybius");

polybius.encode("ATTACK AT 1200", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" }).text;
// "11 42 42 11 13 25 11 42 54 55 53 53"
polybius.decode("11 42 54 55", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" }).text; // "AT12"
polybius.encode("JULIUS", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" }).text; // "24 43 26 23 43 41"
```

The keyword follows the custom alphabet too. Its letters match either case.

```ts
const polybius = create("polybius");

polybius.encode("ATTACK AT 1200", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", key: "ZEBRA5" }).text;
// "15 44 44 15 21 32 15 44 55 56 54 54"
```

The CLI takes the same alphabet:

```bash
ciphers encode polybius "ATTACK AT 1200" --alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
```

That prints `11 42 42 11 13 25 11 42 54 55 53 53`. [secretpy](https://pypi.org/project/secretpy/) 0.12.0 gives the same digits for these squares. It skips the spaces.

## Can a guess spot a bigger square?

A 6 or above in whitespace separated digit pairs gives a wider square away. [`guess`](https://ciphers.agntn.dev/guide/analysis) names the smallest side that fits, but it can't know the alphabet. You'll need to bring that yourself.

```bash
ciphers guess "24 43 26 23 43 41"
```

```text
Family guess (12 characters, 0 A-Z letters, lang=en), most likely first:

1. fractionation (medium): polybius
   Digit pairs with a 6, so a square 6×6 or wider. Polybius reads it with the alphabet that filled it. Character codes pair up the same way.
   Next: ciphers_decode with cipher polybius, which needs alphabet.

Candidates, not a verdict: only a decode that reads settles it.
```

That's a useful clue, not a verdict. Confidence never rises above medium because character codes look the same.

A square can hide its sixth row and column. If a 6×6 ciphertext has no 6, it still reads as the classic 5×5 square with high confidence.

## Smaller squares and missing letters

A custom alphabet folds nothing. Leave J out, and encoding drops it.

```ts
const polybius = create("polybius");

polybius.encode("BADGE", { alphabet: "ABCDEFGHI" }).text; // "12 11 21 31 22"
polybius.encode("JULIUS", { alphabet: "ABCDEFGHIKLMNOPQRSTUVWXYZ" }).text; // "45 31 24 45 43"
```

That first square is a tiny 3×3. The second produces five pairs for six letters. J didn't make the guest list.

When the alphabet has one case, the other matches too. Decoded output uses the alphabet's own symbols.

The result's `options` include the custom alphabet: `{ key: "", alphabet: "ABCDEFGHI" }`. Without one, they're `{ key: "" }`.

## What does the alphabet accept?

Use distinct symbols without whitespace. Its length must be a square number. Four symbols make 2×2, and 81 make 9×9.

Why stop at 9×9? Each coordinate is one digit. Bifid doesn't print those digits, so it has no such ceiling.

Invalid alphabets raise an `InvalidOptionError` naming `alphabet`. A five symbol square can't be drawn:

```text
Invalid option alphabet=ABCDE: must hold a square number of symbols, like 9, 16, 25 or 36, and holds 5
```

Duplicates, whitespace and fewer than four symbols are rejected too. Each message says which rule broke:

```text
Invalid option alphabet=ABCA: has A twice
Invalid option alphabet=AB D: can't hold whitespace, which decoding skips
Invalid option alphabet=ABC: must hold at least 4 symbols
```

## What happens to unknown ciphertext?

Decode reads whitespace separated tokens. A valid two digit coordinate becomes its cell. Anything else stays in place.

```ts
const polybius = create("polybius");

polybius.decode("23 ab 24").text; // "HabI"
```

That's useful for mixed text. It's also a trap: an invalid token doesn't raise an error. Check the output before trusting a solve.


## Sitemap

See the full [sitemap](https://ciphers.agntn.dev/sitemap.md) for all pages.
