Here's the first riddle I invented for Puzzling SE. Hope you'll enjoy solving it.
This story takes place during World War II. A German spy is assigned the task to sneak overnight into a military base near London and steal secret documents of utmost importance.
The documents are kept inside ninety safes of reinforced unbreakable steel, and each safe is protected by a numeric secret code. The only way to get the documents is to open each safe with the correct code. If the wrong code is entered, the safe will immediately trigger a siren which will alert all military personnel, so the spy has only one try available.
German Intelligence was able to intercept the codes of the first fifteen safes, which they communicate to the spy:
Safe Code
#1 2
#2 4
#3 6
#4 8
#5 10
#6 12
#7 14
#8 16
#9 18
#10 20
#11 22
#12 24
#13 26
#14 28
#15 30
The rest of the safes' codes is still unknown. Therefore German Intelligence advises the spy not to tamper with the other safes.
That same night, the spy enters unseen the military base, finds the safes, silently opens each one of the first fifteen safes with the correct code and steals the documents.
However, wanting to steal as many secret documents as possible, the spy starts opening the rest of the safes. The pattern is obvious: a safe's code appears to be the double of the safe's number!
Everything goes well for safe #16 and #17.
However, when the spy enters the code 36 on safe #18, the safe doesn't open; its alarm triggers, and the spy is captured.
Can you find why? If not, continue reading.
After the end of the war, the commander of the base is asked by the High Command to compile a list of all safes and codes. He produces the following document:
Safe Code Safe Code Safe Code Safe Code Safe Code Safe Code
#1 2 #16 32 #31 28 #46 -42 #61 34 #76 46
#2 4 #17 34 #32 30 #47 -40 #62 36 #77 48
#3 6 #18 25 #33 32 #48 -38 #63 38 #78 50
#4 8 #19 38 #34 34 #49 -36 #64 40 #79 52
#5 10 #20 40 #35 36 #50 30 #65 42 #80 25
#6 12 #21 42 #36 38 #51 32 #66 44 #81 27
#7 14 #22 44 #37 40 #52 34 #67 46 #82 29
#8 16 #23 46 #38 42 #53 36 #68 48 #83 31
#9 18 #24 48 #39 44 #54 38 #69 50 #84 33
#10 20 #25 50 #40 -54 #55 40 #70 34 #85 35
#11 22 #26 52 #41 -52 #56 42 #71 36 #86 37
#12 24 #27 54 #42 -50 #57 44 #72 38 #87 39
#13 26 #28 56 #43 -48 #58 46 #73 40 #88 41
#14 28 #29 58 #44 -46 #59 48 #74 42 #89 43
#15 30 #30 26 #45 -44 #60 32 #75 44 #90 38
Can you find now how the codes were chosen - and hence why the spy failed?
Hint 1
There is an unique solution for the riddle. Don't try to find overcomplicated formulas. There is more than just mathematics -- in fact, although there is quite a bit of calculations, the mathematics involved are very basic. To crack the code, you'll have to do some lateral thinking.
Hint 2
Language is important. The story takes place in Great Britain because the riddle is related to the English language. The nationality of the spy is irrelevant.
Hint 3
Observe how the British chose the secret algorithm to fool spies. "Code of safe $n = 2 \times n$" is a red herring -- it looks like it is the solution, but is valid only up to safe #29 with the exception of safe #18. The units for each "ten" follow a pattern, but each "ten" breaks the pattern. Where would you find such a pattern?
EDIT: simplified the puzzle story.