Ciphers · Classical ciphers
Bacon's (Baconian) cipher
Francis Bacon's two-symbol alphabet writes each letter as five A or B symbols, and a message can hide in two typefaces.
Bacon's cipher, devised by Francis Bacon, turns each letter into five symbols that can each take one of two values. Written as A and B, the letter H is AABBB. By itself that's a simple substitution that spends five characters on one letter. The interest, and Bacon's point, is that the two values can hide in anything that has two forms: two typefaces, long and short stems, odd and even words. It's a cipher that hides in plain sight, and a five-bit binary code three centuries before computers. Another symbol cipher with a hiding side is the pigpen cipher, and a number-based one is the Polybius square.
Try it
Nothing you type here leaves your browser.
Encrypt a short secret, then paste a cover text of at least five letters per secret letter. The tool shows the cover with A letters plain and B letters in bold. Choose the 24-letter alphabet to follow Bacon's original table, in which I and J share a code and so do U and V.
The five-symbol code
Each letter becomes a group of five A's and B's, read as a binary number. A is AAAAA, B is AAAAB, C is AAABA, and so on, counting up in binary with A for 0 and B for 1. In the 26-letter version, HIDE becomes AABBB ABAAA AAABB AABAA. Bacon's own table had 24 letters, and the 24-letter version codes HIDE the same way.
| A | B | C | D | E | F | G | H | I | J | K | L | M |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
AAAAA | AAAAB | AAABA | AAABB | AABAA | AABAB | AABBA | AABBB | ABAAA | ABAAB | ABABA | ABABB | ABBAA |
| N | O | P | Q | R | S | T | U | V | W | X | Y | Z |
ABBAB | ABBBA | ABBBB | BAAAA | BAAAB | BAABA | BAABB | BABAA | BABAB | BABBA | BABBB | BBAAA | BBAAB |
The table shows the 26-letter version. Five two-valued symbols give 25 = 32 combinations, more than the 26 (or 24) needed.
The hiding step
Now take an innocent cover text and set each letter in one of two styles, plain for A and bold or italic for B. Reading the styles off gives the A/B string, and groups of five give the secret letters. The cover text for the four groups of HIDE would need 20 letters, and the reader sees only a sentence in two slightly different typefaces. Bacon called this approach omnia per omnia, "anything by anything", meaning any carrier with two distinguishable states will do. Telegraph operators could use short and long pauses, a quilt could use two colors of patch, and a page could use two fonts.
Bacon's own words
Francis Bacon (1561–1626), the English philosopher and statesman, described the biliteral alphabet in The Advancement of Learning in 1605 and gave a longer account in his Latin expansion of the work, De Augmentis Scientiarum. He proposed it as a way to convey a message so that nobody would even suspect it, which makes it steganography (hidden writing) as well as cryptography.
The most modern thing about it is the binary encoding. Every digital system stores letters as groups of two-valued symbols, and Bacon's five-position code uses the same idea as the five-unit telegraph codes of the 1870s (Baudot's, which gave us the word baud). ASCII uses seven bits and Unicode more, but the principle is the same.
Did Bacon write Shakespeare?
One claim deserves a correction. In the nineteenth and twentieth centuries, some people argued that Francis Bacon wrote the plays of Shakespeare and hid his name in them with his biliteral cipher, in the typefaces of the First Folio. Elizabeth Wells Gallup published a "decipherment" in 1899. William and Elizebeth Friedman, two of the leading American codebreakers of the twentieth century, tested the claim and published The Shakespearean Ciphers Examined in 1957. They found that the First Folio was set in many typefaces, not two, and that the printing practices of the time would have made it impossible to transmit a message accurately. They also found that the "ciphers" could be made to give any message at all, because the decipherer decided which letters counted as A and which as B. Scholars have rejected the claim ever since. As a dry coda, the Friedmans' own tombstone at Arlington National Cemetery carries a Bacon-cipher message that went unnoticed for years.
Breaking it
A Bacon cipher is easy to break once you spot the two-valued code. It's a substitution of groups of five symbols, and the usual counting works on the groups. The hard part is finding it. A reader has to notice that a text uses two typefaces, or two kinds of word, or some other binary difference, and then try the table. Digital versions hide even better, since two forms of the same letter can be encoded in invisible characters, which is how some text watermarks work. The frequency analysis tool would show an index of coincidence around 0.5 for a text with only two symbols, and that's the sign to look for.
The cipher offers no security once the method is known, so it belongs with the simple substitution ciphers in strength, and with other steganography in the art of not being noticed.
The code
Bacon's cipher in the 26-letter form.
// Bacon's cipher (26-letter version): each letter's position, 0 to 25, in five binary digits, written with A for 0 and B for 1.
function bacon(text) {
return text.toUpperCase().replace(/[^A-Z]/g, '').split('').map(function (ch) {
var bits = ('00000' + (ch.charCodeAt(0) - 65).toString(2)).slice(-5);
return bits.replace(/0/g, 'A').replace(/1/g, 'B');
}).join('');
}
// Back again: cut the A/B string into groups of five and read each group as a binary number.
function baconDecode(ab) {
var s = ab.toUpperCase().replace(/[^AB]/g, ''), out = '';
for (var i = 0; i + 5 <= s.length; i += 5)
out += String.fromCharCode(65 + parseInt(s.slice(i, i + 5).replace(/A/g, '0').replace(/B/g, '1'), 2));
return out;
}Common questions
Is Bacon's cipher the same as the Baconian cipher?
Yes. Other names are the biliteral cipher and the Baconian cipher. It's called biliteral because it uses two letters, A and B.
Why do the 24-letter and 26-letter versions differ?
Latin in Bacon's time had no separate J and no separate U and V, so his table gave I and J one code and U and V another. Modern versions give every letter its own.
Can I hide a message in a document with Bacon's cipher?
You can, with any two styles that a reader can tell apart. It's steganography, so it relies on nobody looking. Don't use it for real secrets.
How is it related to binary code?
It is a binary code. Each group of five symbols is a number from 0 to 31, and A and B stand for 0 and 1. Modern text encodings do the same with 7, 8 or more bits per character.
On the timeline
- 1605 Francis Bacon describes a binary cipher in The Advancement of Learning.