Bifid
Bifid Cipher
Polybius coordinates, split and re-read.
- Keyspace
- 25! × period variants, 36! on a 6×6
- Decode
- same options back
- Works on
- A-Z with J as I, or the symbols of alphabet, the rest dropped
- Family
- 11 in fractionation
Options
Access
- Create
create("bifid") - CLI
ciphers encode bifid 'FLEE AT ONCE' --key BICONDITIONAL --period 5 - Tryplayground with the sample above
- Kinpolybius, nihilist, morse, fractionated-morse +6
Delastelle's Bifid sends letters through a Polybius square twice. Between trips, it mixes their coordinates. The result is still letters, but their coordinates have wandered.
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. 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:
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.
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:
ciphers encode bifid "DEFEND THE EAST WALL 1941" --alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 --period 5
That prints AAP3ZDGDH2DVABYH39741. 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:
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:
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 lists those messages. Decoding accepts either case when the alphabet has one case only.