The Code Book

(All rights belong to their owners. Images used here for review purposes only.)

The Code Book, by Simon Singh, 1999, Anchor Press
A couple of weeks ago, I was at the Junkudo bookstore near my apartment, and I had a couple hours to kill. Junkudo has a small section of English import books, with 2-3 shelves of science and math books. Apparently, quite a few of these have been in inventory for a long time, and the store has them marked 20% off to get rid of them. I wanted something science-y to read, and it was kind of a toss-up between Fermat’s Last Theorem, and The Code Book, both written by Simon Singh. I’ve got something of a soft spot for codes, and the one had a section on the Beale Cipher, so I picked The Code Book. Unfortunately, the original cover price was $20 USD, and even with the discount came out well over the $11 I could have gotten it for from But, I would have gotten killed on the shipping costs. Besides, I wanted it right then. Such is the price of convenience.

The Code Book originally came out in 1999, and at the back were 10 ciphers that made up the Cipher Contest. My edition of the book was reprinted in 2000, after the contest closed, with the $15,000 USD prize being claimed by 5 Swedes, three of whom had been working on their PhD degrees at the Royal Institute of Technology, Stockholm, at the time. The reprint stated that the contest had ended, but the ciphers were retained for anyone that wanted to work on them themselves. More about this later.

The book is a mix of history and explanation of how the different types of codes work, with the narrative sections being used to give context to the development of increasingly sophisticated ciphers, and the associated methods for breaking them. The story starts out with the trial of Mary, Queen of Scots (1542-1587), on charges of conspiring to assassinate her cousin, Queen Elizabeth. At the heart of her defense was her claim that she’d been completely unaware of what her supporters were planning while she was isolated in prison. Unfortunately for her, the messages between Mary and her followers had all been copied by Walsingham, Elizabeth’s chief spymaster, who had his own cryptographer on staff, Thomas Phelippes. Not only did they know exactly what Mary was discussing with her followers, they forged a letter in her handwriting and in the same code, designed to rat out both Mary and the co-conspirators by name. The rest is, literally, history. The cipher Mary used was a simple letter substitution that could be easily cracked through frequency analysis. From here, the book goes through the invention of the telegraph, telephone, radio and the computer, with stories from ancient Rome, the Renaissance, both World Wars, and up through the creation of the RSA cipher and into speculation about the possible development and use of quantum computers, with a brief foray into the Beale cipher.

The Code Book is a good attempt to introduce readers to cryptography and cryptanalysis, while also providing stories for people that don’t care about the math. It’s not a perfect balance, because occasionally the tales about people like Alan Turing are just superficial snapshots, while the descriptions of how some of the ciphers work are needlessly over-explained. I felt the sections on RSA encryption and quantum computing were especially repetitious and wordy. On the other hand, I can also understand that some readers may need the systems spelled out at that level of detail. Regardless, I do like the book, and I recommend it to anyone interested in cipher history, as well as wanting to learn what the basic types of cipher approaches are.

Quickly, codes are word substitutions, such as when you say “Big Bear” rather than “Oracle Corp.”, and “Little Bear” for Larry Ellison. Ciphers are those systems where you make the text of a message harder to read, such as scrambling the letters around within the text (transposition), or changing A for P, X for E (substitution). Ciphers can be as simple as the Captain Midnight decoder ring (i.e., the Caesar shift cipher), or as convoluted as the Enigma machine and public key encryption. One of the things that I liked about learning how public key encryption works is in how it uses prime numbers, and how that ties to my blog entries on the Riemann zeta function. Also, it was amusing to me to see a mention of Martin Gardner and his Mathematical Recreation columns, where Martin had published the workings of the RSA system in his column, and the avalanche of requests for copies of the RSA paper from its authors that the article generated. (Everything is connected.)

Now, for the cipher contest. As mentioned above, there are 10 messages at the back of the book, ranging from easiest to hardest. Each one is based on one of the systems mentioned in the book, and all of them have already been cracked (if you want to cheat and look for the solutions on the net). The first one was very easy, and was just a random letter substitution. Funny enough, the copy of the message on Singh’s website was truncated, with 60% of the text missing. Even so, that was more than enough to work with. I tackled it initially with just paper and pencil, but when I realized that I didn’t have the entire text, I figured I might as well track the full message down from another website (I didn’t want to hand-type it), and then write a VBscript program to complete the rest of the print out for me. That was fun. The second message was much shorter, and was just a Captain Midnight decoder ring puzzle. I started that one on paper with pencil, too, but the simple substitutions just produced garbage when I tried plugging “the,” “and,” “are,” “was,” etc. into the most common 3-letter word. Then I hit on the idea of rewriting my VBscript program to brute force print out all 25 possible messages by “rotating the decoder ring.” That gave me 25 messages to wade through, but one specific message looked almost like real words. That’s when I realized that the plaintext was in Latin.

The problem is that I’m not particularly good at deciphering stuff, and I’m already busy with 20 other projects I want to finish. So, I don’t want to try tackling any of the other messages from scratch. On the other hand, I can write VBscript relatively well, and I do like seeing the deciphered messages coming out of my scripts (showing that I got the theory right). So, I went to the Swedish team’s website and read through their solutions. Then I wrote another script for decrypting message 4 – a Vigenere cipher. Even knowing what the solution was, I kept introducing bugs into my code, so it took a little over an hour to get it right. I followed that with message 3 (a random letter substitution, but with 6 letters representing “E” to throw off the frequency analysis; took 30 minutes for that script). Then #5 and #6. #5 was a simple book cipher (the count the words in a source text, and each number represents one letter from the text; 30 minutes) and #6 was a Playfair cipher. The Playfair message is pretty interesting, from my viewpoint, and I really did like seeing the plaintext come out at the end. This leaves #7 (ADFGVX) and #8 (Enigma). Then I’ll call it quits.

If there’s enough interest, I might consider writing a short blog series talking about the above ciphers, and how the VBscripts work.

One last comment: I went to the Amazon page for The Code Book, and I looked through the 1-star criticisms. There are only a few, which all complain that the Kindle version of the book is very low-grade and is missing all of the illustrations. So, I recommend that if you do buy the book, you get the paperback version.

Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: