Ciphers · Classical ciphers
The book cipher
Numbers that point into a text you and your reader both have. How a book cipher works, a tool to try one, and the unsolved Beale ciphers.
A book cipher hides a message in numbers that point into a text both sides own. The sender picks words from the book, and each number says which one. Without the book the numbers are noise, and no amount of frequency counting will tell you the letter behind a number. The best-known book ciphers are the Beale ciphers, three pages of numbers that supposedly lead to a buried treasure in Virginia and have been argued over for 140 years.
Try it
Nothing you type here leaves your browser. The random choices come from your browser's secure random number generator.
Encrypt the same letter twice and you get different numbers whenever more than one word begins with that letter, so the output changes every time you press a key. Decrypting works with any of them.
How it works
Number the words of the book from 1. To encrypt a letter, pick any word that starts with it and write down the word's number. The word When, number 1 of the Declaration of Independence, stands for W. in (word 2) stands for I, and the (word 3) for T. The message Meet me at the old stone bridge becomes a list of 25 numbers such as 913 629 213 3 559 33 1141 …, each pointing at a word that begins with the right letter. To decrypt, look up each number and take the first letter of the word.
Three things follow from that.
- The letter statistics are scrambled, not removed. Of the 1,323 words in our copy of the Declaration, 256 start with T, 167 with A and 147 with O, so those letters can be written many different ways. Only 35 words start with E and 41 with R. E is the commonest letter in English and T is second, yet the commonest letter has far fewer numbers to hide behind. The same few E numbers keep recurring, and an attacker who counts repeated numbers will find them. This is the idea of a homophonic cipher, which uses several symbols for the same letter, in a form whose weak spots depend on the book.
- The key is the book, not a short word. It's long and hard to guess, and the sender only has to say "word numbers from the Declaration". It's easy to share and, unlike a codebook, doesn't look like a code.
- Some letters are impossible. Nothing in the Declaration starts with X, Y or Z, so a message that needs them has to be reworded, or those letters spelled out some other way.
Book ciphers differ in what they point at. Some use word numbers, as here. Others use page, line and word, or individual letters, or take the first letter of each word. In every case the key is one specific edition of the book, because a different printing with different words gives nonsense.
The Beale ciphers
In 1885 a pamphlet called The Beale Papers appeared in Lynchburg, Virginia, published by James B. Ward. It tells the story of Thomas J. Beale, who in the early 1800s supposedly buried a large treasure in Bedford County, Virginia, and left a locked box with an innkeeper, Robert Morriss, containing three papers of numbers. The pamphlet reproduces the three ciphertexts, each a list of numbers.
- Number 2 was solved. Whoever solved it used the Declaration of Independence as the key, taking the first letter of the word at each number. It describes two deposits in clay pots about six feet down, with 1,014 pounds of gold and 3,812 pounds of silver in the first and 1,907 pounds of gold, 1,288 pounds of silver and jewels worth about ,000 in the second. That's roughly three tons.
- Number 1 is said to say where the treasure is, and number 3 to list the owners and their next of kin. Neither has been solved.
To make the Declaration key work for number 2, the numbering needs a few edits, since some numbers don't give the right letters with a standard copy of the text. Doubters take that as a sign of trouble. Joe Nickell, among others, argued that Ward wrote the whole story. He cited historical records that cast doubt on Beale's existence, a word ("stampeding") that is too late for the story's date, and stylistic links to Ward. The cryptographer Jim Gillogly published an early hoax argument, "A Dissenting Opinion" (1980). He noted that cipher number 1, tried with the Declaration, produces strings of letters in alphabetical order, which is unlikely to be chance. Cipher number 3 also looks too short for the thirty names it supposedly holds. Many people have tried books and documents as keys for numbers 1 and 3, and none has been confirmed. Whether there's a treasure isn't known. That the story is a hoax is a common view, and not a proven one.
The Beale story shows the weakness of a book cipher along with its strength. Without the book you can't read the message, and if the book is lost, so is the message. If the ciphers are genuine, the two unsolved ones are unsolved because nobody has found the book.
Other uses of book ciphers
Armies and spies have used book ciphers for centuries. The weakness is operational, not mathematical. The book has to be carried and kept secret, a book in a spy's luggage is evidence, and a message under a short key text repeats numbers, which makes it vulnerable. The Bacon cipher and the pigpen cipher hide in how a text looks, while a book cipher hides in a text both sides own. A strong version, with a different text for every message, is in effect a one-time pad made of words.
Breaking it
- Find the book. If you can guess the book, you can read the message. The largest number in a ciphertext gives the minimum length of the book. Beale number 2 has a largest number of 1,005, which a text of about 1,300 words such as the Declaration satisfies. Common candidates are the Bible, Shakespeare, the Declaration of Independence and the dictionary.
- Count the numbers. Even without the book, some numbers repeat, and a number that repeats is a letter that repeats. Numbers that sit close together often belong to the same page. With enough of them you can solve it as a homophonic substitution and then work back to the book.
- Use known plaintext. If a number appears where "the" should be, it points to a word starting with T.
Our tool shows the principle on a short message. A short key text gives few choices per letter and repeated numbers, and a long one gives many. Paste in a different text and watch how the numbers change.
The code
A book cipher on word numbers, with a fair random choice among the matching words.
// Book cipher: a letter becomes the number of a word in the key text that starts with that letter.
function words(key) { return key.match(/[A-Za-z0-9'-]+/g) || []; }
// `rand(n)` must return a fair whole number from 0 to n-1, so each letter hides behind different numbers.
function bookEncode(text, key, rand) {
var w = words(key), byLetter = {};
w.forEach(function (word, i) { var l = word[0].toUpperCase(); (byLetter[l] = byLetter[l] || []).push(i + 1); });
return text.toUpperCase().replace(/[^A-Z]/g, '').split('').map(function (ch) {
var choices = byLetter[ch];
if (!choices) throw new Error('no word starts with ' + ch);
return choices[rand(choices.length)];
});
}
function bookDecode(numbers, key) {
var w = words(key);
return numbers.map(function (n) { return w[n - 1][0].toUpperCase(); }).join('');
}On the timeline
- 1885 The Beale ciphers appear in a pamphlet.