Ciphers · Classical ciphers
The bifid cipher
Split each letter into a row and a column, mix the halves together, then read them back in pairs. Fractionation, worked by hand.
The bifid cipher hides a message by cutting every letter in half and shuffling the halves together. Each letter is looked up in a Polybius square to get a row and a column. All the rows are written out first, then all the columns, and the long string of digits is read off again in pairs. The new pairs name different letters, so every ciphertext letter now depends on two plaintext letters. Félix Delastelle designed it around 1901.
Try it
Nothing you type here leaves your browser.
The key is a keyword or a full 25-letter square. A period of 0 treats the whole message as one block. A number such as 5 cuts it into blocks of that many letters, which is how the cipher was meant to be used on long messages.
How it works
Take the message FLEEATONCE and the square built from the key BGWKZQPNDSIOAXEFCLUMTHYVR. Look up each letter's row and column, both numbered 1 to 5. F is row 4, column 1. L is row 4, column 3. E is row 3, column 5, and so on. Write all the rows on one line and all the columns below it:
Join the two lines to get 4433353243 1355312325. Now read the digits in pairs, 44 33 35 32 43 13 55 31 23 25, and look each pair up in the square again. 44 is U, 33 is A, 35 is E, and so on, which gives the ciphertext UAEOLWRINS. To decrypt, turn the ciphertext letters into digits, write them in one line, split the line in half (the first half is rows, the second is columns) and read the letters back off.
Periods
On a long message, doing it as one block means the first plaintext letter affects letters far down the ciphertext, and the work gets tedious by hand. The usual fix is to cut the message into blocks of a fixed length, the period, and treat each block separately. With FLEEATONCE in blocks of five the result is UAIEYYDINS, a different answer from the whole-message one.
What the mixing buys
A simple substitution turns one letter into one letter. Bifid makes each ciphertext letter depend on two plaintext letters, because its row digit comes from one letter and its column digit from another. That spreading is called diffusion, and fractionation is how bifid gets it. It's far less than a modern cipher manages. Changing one plaintext letter in a 36-letter message changed exactly two ciphertext letters, whatever the period, which is the same two as Playfair and compares with one for Vigenère. In AES, flipping one bit changes about half the output bits (AES-GCM).
History
Delastelle (1840–1902) was a French amateur who spent his life on ciphers. He described the bifid, the two-square, the four-square and the trifid, a three-dimensional bifid that uses a cube of 27 symbols. His book came out in 1902, the year he died. Bifid saw little operational use, but it was popular in puzzle columns and it remains a staple of the American Cryptogram Association. It also shows off fractionation, the idea at the center of the German ADFGVX cipher of 1918 (ADFGVX).
Breaking it
- Find the period. With an even period, letters half a period apart in a block share a coordinate list in a way that shows up in pair statistics, so you can find the period by testing the pair frequencies of letters at that spacing. Odd periods are harder because three plaintext letters are involved, and they need more text.
- Then climb. Once the period is known, a computer can search for the square. Start from a random square, decrypt, score the text with four-letter statistics and keep the improvements. Hill climbing and annealing work, as they do for Playfair.
- Use known plaintext. A few guessed words fix the coordinates of their letters and constrain the rest of the square.
There are 25! squares, about 1.55 × 1025. Add the period and that's more than hand work could ever search, and less than a computer needs.
The code
Bifid over one block. For a period, apply it to each block of that length in turn.
// Bifid: replace each letter by its (row, column), write all the rows then all the columns, and read the digits off in pairs.
// `sq` is the 25-letter square (I and J share a cell). The whole message is one block here; real use cut it into blocks (the period).
function bifid(sq, text, decode) {
var t = text.toUpperCase().replace(/[^A-Z]/g, '').replace(/J/g, 'I').split(''), n = t.length, out = '', i;
if (!decode) {
var rows = [], cols = [];
t.forEach(function (c) { var k = sq.indexOf(c); rows.push(Math.floor(k / 5)); cols.push(k % 5); });
var all = rows.concat(cols);
for (i = 0; i < n; i++) out += sq[all[2 * i] * 5 + all[2 * i + 1]];
} else {
var digits = [];
t.forEach(function (c) { var k = sq.indexOf(c); digits.push(Math.floor(k / 5), k % 5); });
for (i = 0; i < n; i++) out += sq[digits[i] * 5 + digits[n + i]]; // first n digits are rows, the next n are columns
}
return out;
}Common questions
What does "bifid" mean?
Divided into two parts. The cipher divides every letter into a row coordinate and a column coordinate, then recombines them.
What is the period in a bifid cipher?
It's the length of the block of letters encrypted together. A period of 5 encrypts the message five letters at a time, so a long message can be done in pieces. A period equal to the message length makes the whole message one block.
Why is bifid harder than Playfair to attack by hand?
Each ciphertext letter depends on two plaintext letters that may be far apart in the block, not on neighbors. Pair statistics get blurred, though not removed.
Is the bifid cipher the same as trifid?
No. Trifid, also by Delastelle, uses a 3×3×3 cube of 27 symbols and three coordinates per letter, so each ciphertext letter depends on three plaintext letters.
Can the keyword be longer than 25 letters?
The square holds 25 distinct letters. A key of 25 different letters fills the whole square. A shorter keyword goes first and the rest of the alphabet fills in behind it.
On the timeline
- 1901 to 1902 Félix Delastelle devises the bifid, two-square and four-square ciphers, published in 1902.