# The Book Cipher Algorithm

### Practical Issues

The Book cipher is straightforward to implement and secure, but using it in real life presents some difficulties. First of all, you can encrypt only letters, preferably after converting them to uppercase. Most of the crypto textbooks deal with uppercase letters only—introducing symbols that appear very often (such as blanks) or sparsely (such as \$ or the #) gives attackers an unnecessary advantage. On the other hand, sometimes you have to encode a message containing numbers or special symbols, and reading decoded text without blanks is a real pain.

This issue can be resolved by preencoding the plaintext using an algorithm similar to UUENCODE, which produces uppercase letters only. A possible candidate is the Five-Letter Codegroup Filter (www.fourmilab.ch/codegroup). While encoding, you could compress text and even implement some kind of double encryption. Compression is good because the main problem with the Book cipher is the need for a long book. To encode a 5000-character plaintext, you need at least a 5000-word book. In fact, it should be much longer because you cannot expect the frequency of all letters in the text to match the frequency of initial letters of words in the book.

Due to the disproportion in frequencies of all letters and initial letters, the coding process may become impossible, and you could run out of some letters even before you start coding. For example, there are practically no English words beginning with the letter "X"—in the Harry Potter book, there is only one such "word" in the phrase "a fiery X appeared on the door." In other books, the only "words" beginning with "X" are chapter numbers written as Roman numerals. In the second Beale cipher (the only one that was successfully decoded), every "X" was coded as 1005, probably pointing to the word "sexes" in the Declaration of Independence, which was used as a key ("sexes" obviously does not start with "x," but does sound like it). Some books also contain zero words beginning with the letter "Z", unless they contain the word "zero" itself.

Therefore, it seems like a good idea to investigate the frequencies of first, second, third, or even last letters in words, to find out which of them matches the frequency of all letters. We analyzed 14 books, from Pride and Prejudice to The Da Vinci Code, and found out that the distribution of frequencies for the third letter in the word has the best correlation with frequencies of all letters. A possible solution is to let users choose which letter in the word to use, by setting an appropriate parameter.

To get the system rolling, you also have to agree with the correspondent about the books you will use to encode the messages. Using "real" books isn't very practical (OCRing them on both sides introduces different errors). So you will probably use some texts available on the Internet, and you might even consider promoting some of your own essays into "books" for additional security. (If we were running the NSA, we would make sure we had a machine-readable copy of the Library of Congress in a form suitable for fast searching.)

### More Insights

 To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.

# First C Compiler Now on Github

The earliest known C compiler by the legendary Dennis Ritchie has been published on the repository.

# HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

HTML5 Mobile Development: Seven Good Ideas (and Three Bad Ones)

# Building Bare Metal ARM Systems with GNU

All you need to know to get up and running... and programming on ARM

# Amazon's Vogels Challenges IT: Rethink App Dev

Amazon Web Services CTO says promised land of cloud computing requires a new generation of applications that follow different principles.

# How to Select a PaaS Partner

Eventually, the vast majority of Web applications will run on a platform-as-a-service, or PaaS, vendor's infrastructure. To help sort out the options, we sent out a matrix with more than 70 decision points to a variety of PaaS providers.

More "Best of the Web" >>