---
title: "Bifid"
description: "Bifid mixes coordinates in a Polybius square. Choose a period and an alphabet."
canonical_url: "https://ciphers.agntn.dev/ciphers/bifid"
---
# Bifid

> Bifid mixes coordinates in a Polybius square. Choose a period and an alphabet.

<cipher-facts name="bifid">



</cipher-facts>

Delastelle's Bifid sends letters through a [Polybius square](https://ciphers.agntn.dev/ciphers/polybius) twice. Between trips, it mixes their coordinates. The result is still letters, but their coordinates have wandered.

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

bifid.encode("FLEE AT ONCE", { key: "BICONDITIONAL", period: 5 }).text; // "GTDUXDBTUM"
bifid.encode("FLEE AT ONCE", { period: 5 }).text; // "HAAEVSLDSP"
bifid.decode("GTDUXDBTUM", { key: "BICONDITIONAL", period: 5 }).text; // "FLEEATONCE"
```

The keyword changes the square. Spaces disappear before encryption, and decoding doesn't restore them. Pack your own spaces.

## How does Bifid mix coordinates?

Each letter has a row and a column. Bifid takes a block of letters and writes their rows first. Then it writes their columns. It reads that run in pairs and looks them up again.

A letter's coordinates spread across two output letters. That's stronger than plain Polybius. The square gets a second job.

The default square is 5×5, like [Playfair's](https://ciphers.agntn.dev/ciphers/playfair). J folds into I. An optional `key` puts its keyword first in the square. Everything outside the square is dropped. Output is uppercase and has no spaces.

## What does the period do?

`period` sets the block length. It defaults to 5 and must be a positive integer. A period longer than the text makes one block.

A bad period raises an `InvalidOptionError`:

```text
Invalid option period=0: must be a positive integer
```

Matching the period matters when decoding. Otherwise, those coordinates get paired differently. That's a nasty puzzle trap.

## A 6×6 Bifid square with digits

Pass `alphabet` to choose the square's symbols. They fill it row by row, with the keyword first. A 36 symbol alphabet makes a 6×6 square.

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

bifid.encode("DEFEND THE EAST WALL 1941", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", period: 5 }).text;
// "AAP3ZDGDH2DVABYH39741"
bifid.decode("AAP3ZDGDH2DVABYH39741", { alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", period: 5 }).text;
// "DEFENDTHEEASTWALL1941"
```

The year survives. The spaces don't. With an explicit alphabet, J has its own cell here. Nothing is folded. In a 25 letter alphabet without J, J gets dropped instead.

The result's `options` include `{ key: "", period: 5, alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" }`. Without `alphabet`, they're `{ key: "", period: 5 }`.

The CLI takes the same alphabet:

```bash
ciphers encode bifid "DEFEND THE EAST WALL 1941" --alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 --period 5
```

That prints `AAP3ZDGDH2DVABYH39741`. [secretpy](https://pypi.org/project/secretpy/) 0.12.0 agrees, on this square and on the 3×3 below.

## Can Bifid use a smaller square?

Nine symbols make a 3×3 square:

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

bifid.encode("BEAD HIGH CAFE", { alphabet: "ABCDEFGHI", period: 4 }).text; // "BBEAIIFBAEGH"
bifid.decode("BBEAIIFBAEGH", { alphabet: "ABCDEFGHI", period: 4 }).text; // "BEADHIGHCAFE"
```

Every surviving letter must come from `ABCDEFGHI`. That's a tight vocabulary. Nice for a puzzle, less nice for a message.

## What alphabets does Bifid accept?

The alphabet needs distinct symbols and no whitespace. Its length must be a square number, at least 4. That makes 2×2 the smallest square. There's no upper side limit. Why would there be? Bifid never prints its coordinates, so digit counts don't matter.

A bad alphabet raises an `InvalidOptionError` naming `alphabet`:

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

Fewer than four symbols, duplicates and whitespace are refused too. The [Polybius page](https://ciphers.agntn.dev/ciphers/polybius) lists those messages. Decoding accepts either case when the alphabet has one case only.


## Sitemap

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