Beale’s Cipher
December 2, 2016
In the early 1800, Thomas J. Beale mined a large quantity of gold and silver, secretly, some place in the American West, and brought the gold, silver, and some jewels purchased with the treasur to Virginia, where he buried it. He wrote three coded documents that described the location of the buried treasure, the nature of the treasure, and the names of the owners. He never came back to retrieve the treasure. Only the second of those documents has been decoded, and many people, even today, are scouring Bedford County, Virginia, looking for buried treasure. Or so the story goes.
Beale used a variant of a book cipher. He chose a long text as a key, numbered each of the words in the text sequentially, starting from 1, and formed a message by choosing from the key text a word for each character of plain text having the same initial letter as the plain text; the cipher text consists of a list of the sequence numbers of the chosen words. For instance, if the key text is “now is the time” and the plain text is “tin”, then either (3 2 1) or (4 2 1) are valid encipherments. If the key text is long, there will be many duplicates, as we saw with the letter “t”, and the resulting cipher will be reasonably secure. Beale used the 1322 words of the Declaration of Independence as the key text for the second document; the key texts associated with the first and third documents are unknown.
Your task is to write programs that encipher and decipher messages using the Beale cipher; use it to decode the second document. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
This was my 2nd ever programming course assignment, and the one I enjoyed programming the most. Thanks for posting this.
In Python. The Beale cipher is apparently so complicated to use, that Beale (probably) messed up the encoding. It is, of course, a daunting task to set up the encoding with a document of 1322 words without a computer. It is also not really known which version of the Declaration of Independence he used.
Sounds like a good excuse to play around with Unicode and ES6 a little more. ES6 has a number of features that make proper Unicode handling rather easier than in previous versions of Javascript. Notably, strings now support the new iterator protocol that allows us to easily convert strings to arrays of single Unicode characters rather than having to deal with surrogate pairs. For testing this, we will use texts in the Gothic script which uses the astral Unicode codepoints U+10330 to U+1034A, and seems to be reasonably well supported by fonts and browsers. Extant Gothic scripts are mainly religious, but there is one poem in Gothic, “Bagme Bloma”, written by J. R. R. Tolkein. Here we encrypt that poem, using as key text the Gothic version of the Lord’s Prayer. I couldn’t find the texts already in the Gothic script, so we start by converting from latin transliterations.
Here’s the output with the key text, the plain text and the decrypted cipher text, we can see one of the disadvantages of Beale’s scheme – some of the letters do not occur as first letter in the key text so cannot be enciphered:
In Ruby