The Gold-Bug
The Gold-Bug
Edgar Allan Poe's story that taught me about cryptography
2024-01-21
Previous
Home
Next
My middle school years were spent in an English-medium school in<br>India. Among our assigned literature readings was a short story by<br>Edgar Allan Poe named "The Gold-Bug." This story introduced me to<br>cryptography, the science of secret messages.
Every time you swipe your credit card to buy something, or log into<br>your bank account, you're using cryptography. Modern life is built on<br>top of certain major advances in this field since World War II, and<br>Edgar Allan Poe's story played a role in inspiring the people who made<br>them.
The Gold-Bug and Poe
The Gold-Bug is not much of a story, as far as plot and character<br>go. While collecting a rare beetle on a beach, a white man and his<br>black manservant discover an old parchment paper with a message<br>written in strange symbols, some sort of secret code.
The story spends most of its pages explaining how the man cracks the<br>code to discover where a pirate's treasure is buried. Still, it's got<br>enough atmosphere of mystery with a hint of the macabre, with<br>disappearing ink, skulls nailed on trees, and a good body count, to<br>hook a young person.
At the time, I had no idea who Edgar Allan Poe was, and how old this<br>story was. But since coming to Boston, where he was born and where the<br>city has a statue of him on Boylston Street, I've learned more about<br>the tortured writer's life and his obsessions. His 215th birthday<br>would have been last week.
It was around 1840 that Poe's fascination with logic and reasoning led<br>him to study the encoding of information. In those days, most people<br>thought of the art of writing secret messages as a kind of occult<br>magic. Poe, however, ever the rationalist, dismissed such<br>fancies. Anyone could write and break secret messages via logical<br>reasoning.
He wrote "The Gold-Bug" as an introduction to the topic, then<br>submitted it to a Philadelphia newspaper's writing contest and won a<br>hundred dollars for it. The paper published it in 1843. It's probably<br>the oldest piece of fiction to incorporate cryptography, and certainly<br>the first to use the term.
The Puzzle
The secret message in the story is an example of a simple<br>substitution cipher, where each letter in a piece of text is<br>replaced by some number or symbol. To read the message, you need a<br>key, a table that shows which symbol stands for which letter.
These substitution ciphers can be decoded without a key by<br>systematically applying logical reasoning and exploring different<br>possibilities.
Assuming the message is in English, you start with a table of how<br>frequently various letters, sequences of letters, and words appear in<br>typical English-language text: e is the most frequent letter,<br>followed by taoinshrdl and so on. In the story, the protagonist<br>counts the frequencies of the symbols on the parchment and writes out<br>an entire table: 8 is the most frequent character,<br>semicolon is the next most frequent, then 4, and so on.
This analysis gives you a place to start. Perhaps 8 stands for e,<br>semicolon stands for t, etc. You try these substitutions to see if<br>the message spells out English words, and if you see mistakes, you can<br>change them until you have figured out the key.
This kind of analysis is similar to the mathematical models needed to<br>generate text, as I discussed in an earlier blog<br>post about generative text models<br>like ChatGPT. Claude Shannon, who laid the foundations of information<br>theory after World War II, once told an interviewer that he had read<br>The Gold-Bug as a child.
Addendum
When I first read this story in middle school, I used the cipher<br>devised by the protagonist to uncover the secret message. But the<br>resulting message was not correct: it produced the word "fosty"<br>instead of "forty."
The story as published in various outlets has different mistakes in<br>the typography of the parchment paper. I have seen at least three<br>different versions with different mistakes.
The version in the picture above is the scan in the Gutenberg website.<br>It has the same mistake as the one I read, producing the word "fosty"<br>in the resulting message. But it couldn't have been Poe's fault. By<br>the time he wrote The Gold-Bug, Poe had done a pretty thorough<br>analysis of hundreds of messages submitted by his readers in response<br>to his essays on cryptography in another magazine.
Fortunately, we now have the original version of the story<br>painstakingly scanned and proof-read by The Edgar Allan Poe Society of<br>Baltimore on their<br>website. They have<br>scanned The Gold-Bug from the original Dollar Newspaper, where it<br>appears without any mistakes:
5 3 ‡ ‡ † 3 0 5 ) ) 6 * ; 4 8 2 6 ) 4 ‡<br>. ) 4 ‡ ) ; 8 0 6 * ; 4 8 † 8 ¶ 6<br>0 ) ) 8 5 ; 1 ‡ ( ; : ‡ * 8 † 8<br>3 ( 8 8 ) 5 * † ; 4 6 ( ; 8 8 * 9 6 * ? ; 8 )<br>* ‡ ( ; 4 8 5 ) ; 5 * † 2 : * ‡<br>( ; 4 9 5 6 * 2 ( 5 * — 4 ) 8 ¶ 8 * ; 4 0<br>6 9 2 8 5 ) ; ) 6 † 8 ) 4...