Book Cipher Decoder & Encoder: The Valley of Fear Cipher

πŸ•·οΈ A Professor Moriarty tool β€” The spider at the centre of the web

A book cipher hides a message as a list of numbers, each pointing to a word in a book that only the sender and receiver share. It is the cipher Fred Porlock, Moriarty's reluctant informer, sent to Baker Street in The Valley of Fear: "534 C2 13 127 36…". Encode your own messages against a classic Holmes passage or any text you paste, decode number lists with the matching words lit up in the book, and follow Holmes step by step as he works out that the key is Whitaker's Almanack. The canon's other secret codes are here too.

  • βœ… Free
  • πŸ”“ No sign-up
  • 🌐 Runs in your browser

Worked example: decoding the Valley of Fear cipher

This is the cipher Fred Porlock sent to Sherlock Holmes at the start of The Valley of Fear. The numbers point to words on one page of a book that Holmes had to identify without being told.

534 C2 13 127 36 31 4 17 21 41 DOUGLAS 109 293 5 37 BIRLSTONE 26 BIRLSTONE 9 47 171

  1. 534 is a page number, so the key is a large book.
  2. C2 means column two, so the book is printed in double columns.
  3. Porlock expected Holmes to own the book, so it is common and identically printed in every copy: Whitaker's Almanack.
  4. This year's edition gives nonsense ("Mahratta Government pig's-bristles"); last year's gives the message.
  5. Each remaining number is the position of a word in that column. Names not in the column, DOUGLAS and BIRLSTONE, are written in clear.
Porlock's cipher, token by token
534C21312736314
page 534 of the almanaccolumn 2Thereisdangermaycome
172141DOUGLAS1092935
verysoononeDouglas (in clear)richcountrynow
37BIRLSTONE26BIRLSTONE947171
atBirlstone (in clear)HouseBirlstone (in clear)confidenceispressing

β€œThere is danger may come very soon one Douglas rich country now at Birlstone House Birlstone confidence is pressing.”

Porlock had to make do with the words in one column, so the message is clipped, and "confidence" stands in for "confident". The almanac page itself is never printed in the story, so you need the same text to decode a book cipher: the tool above lets you pick one and does the counting.

The Gloria Scott hidden message

In Holmes's first case, the warning is hidden in plain sight. Read every third word, starting with the first:

The supply of game for London is going steadily up. Head-keeper Hudson, we believe, has been now told to receive all orders for fly paper and for preservation of your hen pheasant's life.

β€œThe game is up. Hudson has told all. Fly for your life.”

What it does

πŸ“–

Encoder and decoder

Pick a public-domain Holmes passage or paste your own book. Words with several matches are chosen at random; missing words are spelled from initials or left in clear, as Porlock did.

βœ‰οΈ

Porlock's message, solved

Follow Holmes's reasoning from "534" to Whitaker's Almanack, see why the new edition fails, and watch the warning about Douglas of Birlstone appear word by word.

πŸ•―οΈ

The canon's other codes

Read every third word of the Gloria Scott note, hide your own message in an innocent letter, and signal with the Red Circle candle code.

How to use it

  1. 1

    Choose a key text, or paste a book you and your correspondent both have.

  2. 2

    Type a message to get its word numbers, or paste numbers to decode them.

  3. 3

    Copy the cipher or a share link. Without the same book, it is just numbers.

What is a book cipher?

A book cipher replaces each word of a message with a number that points into a book. Sender and receiver agree on the book in advance; the message travels as a list of numbers. Variants count words on a given page, use page-line-word triples, or take only the first letter of each word to spell things out.

Without the book, the numbers are close to meaningless, which is why book ciphers were used by spies and soldiers for centuries. Their weakness is the book itself: if an enemy guesses or finds it, every message falls at once. That is exactly how Holmes breaks Porlock's cipher. He never sees the key; he deduces which book it must be.

How Holmes solved the Valley of Fear cipher

The Valley of Fear opens with a coded note from Fred Porlock, an agent of Professor Moriarty who secretly feeds Holmes information. It reads "534 C2 13 127 36 31 4 17 21 41 DOUGLAS 109 293 5 37 BIRLSTONE 26 BIRLSTONE 9 47 171". The key was to follow, but Porlock loses his nerve and never sends it.

Holmes reasons from the cipher alone. 534 must be a page, so the book is large. C2 is not "chapter two" but "column two", so it is printed in double columns, and long ones, since one word is number 293. Porlock expected Holmes to own it, so it is a common book with standard pagination. The Bible has too many editions, Bradshaw's railway guide and the dictionary have too narrow a vocabulary, which leaves an almanac: Whitaker's.

His first try, with the new year's edition, gives "Mahratta Government pig's-bristles". Then he realises that it is 7 January and Porlock would have used the old one. Last year's almanac gives: "There is danger may come very soon one Douglas rich country now at Birlstone House Birlstone confidence is pressing."

The other ciphers in Sherlock Holmes

In "The Gloria Scott" (1893), Holmes's earliest case, old Trevor dies of shock after reading a note about game birds. Holmes finds the warning hidden in every third word: "The game is up. Hudson has told all. Fly for your life." This kind of null cipher hides a message among innocent filler words.

In "The Adventure of the Red Circle" (1911), an Italian signals to his wife with a candle: one flash for A, two for B, up to twenty-six for Z. Holmes and Watson count along from across the street and read "Attenta" (beware) and "Pericolo" (danger). The best-known Holmes cipher of all, the stick figures of "The Dancing Men", has its own tool on this site.

Everything runs in your browser: no account, no AI, nothing sent anywhere. The bundled key texts are public-domain passages from Arthur Conan Doyle.

Frequently asked questions

How do I decode a book cipher?

You need the same book, or text, that the sender used. Number its words from the start (or from the page and column the cipher names), then look up each number in turn. Paste the numbers and the text into this tool and it does the counting for you, highlighting each word in the text.

What was the cipher in The Valley of Fear?

Porlock's message was "534 C2 13 127 36 31 4 17 21 41 DOUGLAS 109 293 5 37 BIRLSTONE 26 BIRLSTONE 9 47 171". Page 534, column 2 of the previous year's Whitaker's Almanack gives: "There is danger may come very soon one Douglas rich country now at Birlstone House Birlstone confidence is pressing."

Why did Holmes think the key book was an almanac?

The cipher pointed to page 534 and column 2, so the book was large and printed in double columns. Porlock assumed Holmes owned it, so it had to be common and identically paginated in every copy. That ruled out the Bible (too many editions), Bradshaw and the dictionary (too limited a vocabulary), leaving Whitaker's Almanack.

Can a book cipher be broken without the book?

With difficulty. A long message can leak patterns, since common words like "the" repeat, which is why good practice picks different occurrences of a repeated word, as this encoder does. In practice book ciphers are broken by finding the book, as Holmes did.

What do the dotted numbers and capital words mean?

If a word is not in the key text, the encoder can spell it from the first letters of other words, written as dotted groups such as 12.40.7. Or it can leave the word in clear, in capitals, just as Porlock had to write DOUGLAS and BIRLSTONE.

What is the Gloria Scott cipher?

A null cipher: the real message is every third word of an innocent-looking note about game birds. "The supply of game for London is going steadily up…" hides "The game is up. Hudson has told all. Fly for your life."

πŸš€ Launch Porlock's Book Cipher