# Treasure Trails/Guide/Ciphers

Ciphers are a method of encrypting information. In Old School RuneScape, ciphers are used as a step in a Treasure Trail. They use a Caesar Shift in order to encrypt an NPC's name.

A Caesar shift is a change of location in the regular alphabet, for example ABC becomes BCD if shifted once to the right/forward.

To solve a more difficult shift (26 combinations) here is a method: we must first count the number of times a letter appears within the cipher. For this example, the clue "BMJ UIF LFCBC TFMMFS" will be used. Make a list of the letters and how many times they appear:

• B = 2
• M = 3
• J = 1
• U = 1
• I = 1
• F = 4
• L = 1
• C = 2
• T = 1
• S = 1

As we can see, "F" is the most common letter within the cipher. Now, the letter "E" is the most common letter in the English language, so we always presume the most common letter in the cipher is "E" as our starting letter. It may turn out to not be the case, but it's a good place to start. So, because "F" is our most common letter in the cipher - we can presume "F" = "E". Once this presumption is made, we write out the entire alphabet in the correct order.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Next, under the letter "E", we write "F" because we think that letter "F" in the cipher is equal to "E" in the alphabet, and then fill out the rest of the alphabet starting from "F" and then looping back to the start once we reach "Z" to give us all letters like such:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

B C D E F G H I J K L M N O P Q R S T U V W X Y Z A

So, we now have a table of sorts where the ciphered letters are on the bottom row, and the corresponding alphabet letter is on the top. So, if our cipher had the letter "Z" in it, for example, we could look for "Z" on the bottom row - look up and see that Z = Y. Now, we have this table; we can see if we are correct in our presumption that "e" was indeed "f" in the cipher. Remember - to decipher, you look at the ciphered message letter on the bottom and then read whatever the top letter is to read what it actually means. If you are enciphering a message, it would be the opposite way round. In our example and using the above table, our "BMJ UIF LFCBC TFMMFS" clue becomes "ALI THE KEBAB SELLER".

Now, in this example - our presumption that "e" is equal to "f" on the grounds the "f" is the most common letter in the cipher and that "e" is the most common letter in English was true - and "e" became our key to the cipher. However, in others it may not be so easy. For example - in the clue "ZCZL", "e" is not the key as that returns the answer "EHEQ". While it is possible it is doubly encrypted, we should explore other alternate keys instead. The next port of call if "e" is not the key is to use vowels, namely "A, E, I, O, U and Y" - as every word in English contains at least one of those letters. If we try using "A" as the key to the cipher, we get "Adam" - which is correct. However, if this was not the case - you should work your way through all vowels. If one of these is not the key, then go through the rest of the letters periodically until you find your solution.

### Cipher Solvers

Another way to solve Caesar ciphers is by brute-forcing them, i.e. to try every possible decryption. This is hard to do by hand, but easy with programming. The following program will print all 26 possibilites, of which only one of them will decrypt to a meaningful phrase.

#### Python

```def caesar(text, shift):
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
translation_map = str.maketrans(alphabet, shifted_alphabet)
return text.translate(translation_map)

encrypted_phrase = "ESBZOPS QJH QFO"

for shift in range(26): print(shift, caesar(encrypted_phrase, shift))
```

#### Lua

```function caesar(text, shift)
out, subst = text:gsub('%a', function(s)
local base = s:lower() == s and ('a'):byte() or ('A'):byte()
return string.char((s:byte() - base + shift) % 26 + base)
end)
return out
end

local phrase = "ESBZOPS QJH QFO"

for shift = 0, 25 do print(string.format('%i %s', shift, caesar(phrase, shift))) end
```

#### Ruby

```str = "ESBZOPS QJH QFO".chars
26.times do |i|
p str.join('').upcase.tr(("A".."Z").to_a.join, ("A".."Z").to_a.rotate(i).join)
end
```

This prints the following table:

```0 ESBZOPS QJH QFO
1 FTCAPQT RKI RGP
2 GUDBQRU SLJ SHQ
3 HVECRSV TMK TIR
4 IWFDSTW UNL UJS
5 JXGETUX VOM VKT
6 KYHFUVY WPN WLU
7 LZIGVWZ XQO XMV
8 MAJHWXA YRP YNW
9 NBKIXYB ZSQ ZOX
10 OCLJYZC ATR APY
12 QENLABE CVT CRA
13 RFOMBCF DWU DSB
14 SGPNCDG EXV ETC
15 THQODEH FYW FUD
16 UIRPEFI GZX GVE
17 VJSQFGJ HAY HWF
18 WKTRGHK IBZ IXG
19 XLUSHIL JCA JYH
20 YMVTIJM KDB KZI
21 ZNWUJKN LEC LAJ
22 AOXVKLO MFD MBK
23 BPYWLMP NGE NCL
24 CQZXMNQ OHF ODM
25 DRAYNOR PIG PEN
```

where the last decrypted text is the one we want.

### X Marks the Spot

Cipher Solution Location
ESBZOPS QJH QFO Draynor Pig Pen Draynor Village, north of the market.

### Medium Ciphers

HQNM LZM STSNQ Iron Man tutor Lumbridge 666
BMJ UIF LFCBC TFMMFS Ali the Kebab seller Pollnivneach 399
ECRVCKP MJCNGF Captain Khaled Large eastern building in Port Piscarilius 5
GUHCHO Drezel Paterdomus temple; Drezel can be found in the cave north of the Paterdomus temple, which lies next to Canifis. Drezel is also an NPC for several quests (fairy code CKS and then go north-west to the end of the bridge, where you can climb down the trapdoor to find Drezel) 7
QSPGFTTPS HSBDLMFCPOF Professor Gracklebone Arceuus Library, ground floor (fairy ring code CIS, if 80,000 coins paid) 9
USBJCPSO Traiborn Wizards' Tower, 1st floor[UK]2nd floor[US] (fairy ring code DIS) 3150