{"id":2052,"date":"2021-03-31T05:25:46","date_gmt":"2021-03-31T05:25:46","guid":{"rendered":"https:\/\/cml-a.com\/content\/?p=2052"},"modified":"2021-03-31T05:25:46","modified_gmt":"2021-03-31T05:25:46","slug":"lord-of-the-rings-snes-password-format","status":"publish","type":"post","link":"https:\/\/cml-a.com\/content\/2021\/03\/31\/lord-of-the-rings-snes-password-format\/","title":{"rendered":"J.R.R. Tolkien\u2019s Lord of the Rings SNES Password Format"},"content":{"rendered":"\n<p>This is an explanation of the formats of the password used in the game. I found this information by trying different passwords and seeing what is accepted by the game and what the effects were. Since this process didn't involve a debugger it could have been done on the console, but using an emulator sped this up a lot.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2021\/03\/image-2.png\" alt=\"\" class=\"wp-image-2068\"\/><\/figure>\n\n\n\n<p>This game has a hugely long password (48 characters.)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/cml-a.com\/content\/wp-content\/uploads\/2021\/03\/image-1.png\" alt=\"\" class=\"wp-image-2055\"\/><\/figure>\n\n\n\n<p>Each alphanumeric character is one of<br><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> .BCDFGHJKLMNPQRSTVWXYZ0123456789<\/code><\/pre>\n\n\n\n<p>That's a '.', the letters of the alphabet with no vowels plus the numbers 0 through 9. This gives 32 choices in total.<\/p>\n\n\n\n<p>The general layout of the password is: (where '.' represents an alphanumeric character)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>             Samwise   Merry           Frodo   Pippin    \n            [       ][       ]       [       ][       ]  \n             .  .  .  .  .  .         .  .  .  .  .  .   \n                                                         \n                                                         \n                                                         \n            Legolas   Aragorn          Gimli   Gandalf   \n            [       ][       ]       [       ][       ]  \n             .  .  .  .  .  .         .  .  .  .  .  .   \n                                                         \n                                                         \nSpawn location              keys              Checksum   \n            [ ][         and events          ][       ]  \n             .  .  .  .  .  .         .  .  .  .  .  .   \n                                                         \n                                                         \n                             Inventory                   \n            [                                         ]  \n             .  .  .  .  .  .         .  .  .  .  .  .   \n<\/code><\/pre>\n\n\n\n<p>As shown above there's<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>3 characters for each of the 8 people in the fellowship (Boromir isn't joinable)<\/li><li>1 character for your spawn location<\/li><li>8 characters representing keys and events<\/li><li>3 characters for checksum<\/li><li>and a 12-character inventory code at the bottom labeled 'INVENTORY CODE' in the password input screen.<\/li><\/ul>\n\n\n\n<p>Following goes into more detail for each of these.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Password characters<\/h2>\n\n\n\n<p>The alphanumeric password is a convenience (lol) for the user. Internally the game maps each character in a password to a number.<br>\nThe mapping is this<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Character | Value \n------------------\n   .      |  0    \n   B      |  1    \n   C      |  2    \n   D      |  3    \n   F      |  4    \n   G      |  5    \n   H      |  6    \n   J      |  7    \n   K      |  8    \n   L      |  9    \n   M      |  10   \n   N      |  11   \n   P      |  12   \n   Q      |  13   \n   R      |  14   \n   S      |  15   \n   T      |  16   \n   V      |  17   \n   W      |  18   \n   X      |  19   \n   Y      |  20   \n   Z      |  21   \n   0      |  22   \n   1      |  23   \n   2      |  24   \n   3      |  25   \n   4      |  26   \n   5      |  27   \n   6      |  28   \n   7      |  29   \n   8      |  30   \n   9      |  31  <\/code><\/pre>\n\n\n\n<p>In the sections that follow, these numerical representations of password characters get used and there is math done on them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">People in the fellowship<\/h2>\n\n\n\n<p>For each joinable person in the fellowship there's a three-character code that encodes their level and equipment.<\/p>\n\n\n\n<p>Firstly, if the three character code is all '.' (value zeroes), that character is not in your party. Otherwise yes they are in your party.<\/p>\n\n\n\n<p>The way in which the codes determine equipment is a bit convoluted and broken. The reason I say that is there are some <br> passwords that are accepted by the game but will either crash the game or cause corrruption while you're playing. The charts and things below describe passwords which are accepted and also don't crash or corrupt the game. <\/p>\n\n\n\n<p>You can find situations (e.g., what if Code3, described below, is less than 16?) where the password gets accepted, the level gets loaded and things appear okay but corruption happens when you go into the menu for example. I reverse engineered what level\/items you get in <em>those<\/em> cases too, and they're accounted for in the source code of my password editor. I'm leaving them out of  this document so that these formulas stay neat and concise as they're specified, because those don't follow the rules listed below. If you want you can see <a href=\"https:\/\/github.com\/clandrew\/lotrpwcheck\/blob\/674d4a42d05f57e6b1e0fedc47d57537dc4ff551\/CharacterUI.cs#L209\">source code here<\/a> for more info on them<\/p>\n\n\n\n<p>So anyway, each person in the fellowship gets a three-character code in the password. Call the three characters in the code <br>\nCode1, Code2, and Code3 in order.<\/p>\n\n\n\n<p>For example if the password contained 'B89' then Code1=1, Code2=30, Code3=31 referring to the chart above. Yes, each of<br> Code1, Code2 and Code3 is a number between 0 and 31 inclusive.<\/p>\n\n\n\n<p>Level is decided by the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (Code1 &lt; 10)\n\tLevel = (Code2 mod 8) * 20 + Code1\nelse\n\tLevel = (Code2 mod 8) * 20 + (Code1 mod 16) + 10<\/code><\/pre>\n\n\n\n<p>The 'mod' operator here is modulus. I.e., A mod B is the remainder when A is divided by B.<\/p>\n\n\n\n<p>Armor is decided by the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> PW char 2  |     Code2      | Armor                          \n--------------------------------------------------------------\n. through F |  0 through 4   | If Code3 is even, Cloth Cloak. \n            |                | If Code3 is odd, Plate Mail.   \n--------------------------------------------------------------\n. through F |  0 through 4   | If Code3 is even, Cloth Cloak. \n            |                | If Code3 is odd, Plate Mail.   \n--------------------------------------------------------------\nK through P |  8 through 12  | If Code3 is even, Padded Armor.\n            |                | If Code3 is odd, Mithril Armor \n--------------------------------------------------------------\nT through Y |  16 through 20 | Leather Armor                  \n--------------------------------------------------------------\n2 through 6 |  24 through 28   Chain Mail                     \n<\/code><\/pre>\n\n\n\n<p>Weapons are decided by the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PW char 3| Code3 | Weapon        \n ----------------------------  \n  T      |  16   | Old Dagger    \n  V      |  17   | Old Dagger    \n  W      |  18   | Dagger        \n  X      |  19   | Dagger        \n  Y      |  20   | Barrow Dagger  \n  Z      |  21   | Barrow Dagger  \n  0      |  22   | Troll Dagger  \n  1      |  23   | Troll Dagger  \n  2      |  24   | Elvish Dagger  \n  3      |  25   | Elvish Dagger  \n  4      |  26   | Sting         \n  5      |  27   | Sting         \n  6      |  28   | Light Sword   \n  7      |  29   | Light Sword   \n  8      |  30   | Sword         \n  9      |  31   | Sword   <\/code><\/pre>\n\n\n\n<p>The password encoding for level, weapon and armor works the same for each of the 8 joinable characters.<\/p>\n\n\n\n<p>Fun fact: if you enter an only-partially-valid password that includes some configuration for a character (e.g., the string is not all '.'), it permanently adds the character to your party until SNES reset. Even if the password is rejected. This leads to a well-known cheesy trick where you can&nbsp;<a href=\"https:\/\/www.gamespot.com\/j-r-r-tolkiens-the-lord-of-the-rings-volume-1\/cheats\/\">enter a bad password<\/a>, press start and hear the \"invalid password\" noise, then delete it and start the game with all the Fellowship unlocked. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Spawn Location<\/h2>\n\n\n\n<p>This is the place in the game world your party will be in after the password gets accepted.<br>\nIt's a 1-character code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PW char| Code | Location             \n-------|------|------------          \n  .    |  0   | Hobbiton             \n  B    |  1   | Brandywine Bridge    \n  C    |  2   | Farmer Maggot        \n  D    |  3   | Ferry                \n  F    |  4   | Crickhollow          \n  G    |  5   | Tom Bombadil's House \n  H    |  6   | Barrow Downs Stones  \n  J    |  7   | Crossroads           \n  K    |  8   | Rivendell            \n  L    |  9   | Moria entrance       \n  M    |  10  | Moria 1 (glitched)   \n  N    |  11  | Moria 2 (glitched) <\/code><\/pre>\n\n\n\n<p>For the last two Moria locations, the game will include those location codes in the passwords it provides to you when you're in Moria.<\/p>\n\n\n\n<p>However, it won't accept the passwords the next time you start the game \ud83d\ude41 (Update: unless you have my bug fix described in <a href=\"https:\/\/cml-a.com\/content\/2021\/04\/06\/lord-of-the-rings-snes-bugfix\/\">this post)<\/a><\/p>\n\n\n\n<p>Might want to keep a map of Moria, you definitely don't want to do it more than once if you can help it<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Keys and events<\/h2>\n\n\n\n<p>These control the state of various unlockable doors and questlines. I haven't investigated which bits control what because it wasn't important to what I was trying to do.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Checksum<\/h2>\n\n\n\n<p>The checksum exists to stop you from trying random passwords and cheating. It's a way of making sure the only passwords accepted are ones the game has actually given to you, not ones you randomly made up yourself.<\/p>\n\n\n\n<p>However, the checksum is pretty easy to understand if you look at the various passwords it gives you. For example, you'll see that leveling up or changing equipment only changes the first character. And using something in your inventory only changes the third character. And, you know how the password characters translate to character codes and there are 32 of them, and modulus kinds of operations are common and inexpensive for computing checksums.<\/p>\n\n\n\n<p>The first character is the 'party checksum':<br>\n    partySum = the sum of the character codes of the first two lines of the password<br>\n    checksumCode = remainder when partySum is divided by 32. (For example, if partySum is 33, the checksumCode is 1.)<\/p>\n\n\n\n<p>The second character is the 'event checksum':<br>\n    eventSum = the sum of the character codes in the \"spawn location\" and \"keys and events\" part of the password<br>\n    checksumCode = remainder when eventSum is divided by 32<\/p>\n\n\n\n<p>The third character is the 'inventory checksum':<br>\n    inventorySum = the sum of the character codes in the \"inventory\" part of the password<br>\n    checksumCode = remainder when inventorySum is divided by 32<\/p>\n\n\n\n<p>This gives you the first, second and third characters of the checksum in order. <\/p>\n\n\n\n<p>I think they put the checksum in the middle of the password to obfuscate it a little bit.<\/p>\n\n\n\n<p>If you're trying to troubleshoot, know that valid checksum doesn't necessarily mean the password will be accepted. The game sometimes rejects passwords for reasons other than invalid checksum. For example, if you specify an invalid location code like 'Z'.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inventory<\/h2>\n\n\n\n<p>These character codes store your inventory state pretty compactly. <br> Each item corresponds to 1 bit within a byte. Not all the bits are used, which is why a full inventory's password code looks like \"9S9S9S 9S9S9S\" rather than all 9s (all 9s means all bits set).<\/p>\n\n\n\n<p> There are 12 inventory code characters in all, which I'm calling code 0 through 11. <\/p>\n\n\n\n<p>For readability the bit is written as a hexadecimal flag.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Item                |Code #| Bit      \n--------------------------------    \nTomb Key            |  0   | 0x1      \nMoria Key           |  0   | 0x2      \nRed Gateway Gem     |  0   | 0x4      \nElvish Book         |  0   | 0x8      \nMagic Rock          |  0   | 0x10     \n\nBottle              |  1   | 0x1      \nLost Amulet         |  1   | 0x2      \nMaggot Note         |  1   | 0x4      \nScroll Of Floi      |  1   | 0x8      \n\nGate Key            |  2   | 0x1      \nMoria Key           |  2   | 0x2      \nYellow Gateway Gem  |  2   | 0x4      \nBook Of The Ages    |  2   | 0x8      \nGold Piece          |  2   | 0x10     \n\nJug Of Honey        |  3   | 0x1      \nLost Amulet         |  3   | 0x2      \nOld Willow Note     |  3   | 0x4      \nScroll Of Oin       |  3   | 0x8      \n\nTomb Key            |  4   | 0x1      \nMoria Key           |  4   | 0x2      \nGateway Keystone    |  4   | 0x4      \nBook Of Mazarbul    |  4   | 0x8      \nGold Pieces         |  4   | 0x10     \n\nEye Glasses         |  5   | 0x1      \nLost Amulet         |  5   | 0x2      \nNote From Gandalf   |  5   | 0x4      \nColor Scoll         |  5   | 0x8      <\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Item                |Code #| Bit \n---------------------------------\nTomb Key            |  6   | 0x1 \nMoria Key           |  6   | 0x2 \nGreen Gateway Gem   |  6   | 0x4 \nBilbo Diary         |  6   | 0x8 \nGold Pieces         |  6   | 0x10\n\nHealing Moss        |  7   | 0x1 \nLost Amulet         |  7   | 0x2 \nLetter To Elrond    |  7   | 0x4 \nKeystone Scroll     |  7   | 0x8 \n\nTomb Key            |  8   | 0x1 \nBoat Oar            |  8   | 0x2 \nPurple Gateway Gem  |  8   | 0x4 \nJeweled Ring        |  8   | 0x8 \nGold Pieces         |  8   | 0x10\n\nAthelas Major       |  9   | 0x1 \nLost Amulet         |  9   | 0x2 \nHorn Of Boromir     |  9   | 0x4 \nLong Bow            |  9   | 0x8 \n\nKey To Bree         |  10  | 0x1 \nHealing Mushroom    |  10  | 0x2 \nViolet Gateway Gem  |  10  | 0x4 \nThe Ring            |  10  | 0x8 \nAthelas Minor       |  10  | 0x10\n\nHealing Fruit       |  11  | 0x1 \nLost Amulet         |  11  | 0x2 \nMagic Fern          |  11  | 0x4 \nOrb of Drexle       |  11  | 0x8 <\/code><\/pre>\n\n\n\n<p>The inventory codes come from bitwise OR-ing the corresponding bits together for each inventory item you have. <\/p>\n\n\n\n<p>For example, suppose you have the first tomb key and the red gateway gem. This is bit '0x1' and '0x4'. When you bitwise-OR these, you get '5'. Code 5 corresponds to password code 'G', from the chart all the way at the top. So if those two are the only items you have, your inventory code in the password is 'G\u2026.. \u2026\u2026'.<\/p>\n\n\n\n<p>For another example, suppose all you have is the first tomb key and the Orb of Drexle. This is bit '0x1' of the first code, and '0x8' of the last. So if those were the only two items you have, your inventory code in the password is 'B\u2026.. \u2026..K'.<\/p>\n\n\n\n<p>There's one special case- although there's an inventory bit allocated to the One Ring, the ring is always in your inventory regardless of whether it's encoded in the password or not.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Links<\/h2>\n\n\n\n<p>Hope you found this helpful<\/p>\n\n\n\n<p>All this information is used in a password editor I made. That is here<br><a href=\"https:\/\/github.com\/clandrew\/lotrpwcheck\/\">https:\/\/github.com\/clandrew\/lotrpwcheck\/<\/a><\/p>\n\n\n\n<p>To view this post in text form, it's here<br><a href=\"https:\/\/raw.githubusercontent.com\/clandrew\/lotrpwcheck\/master\/Format.txt\">https:\/\/raw.githubusercontent.com\/clandrew\/lotrpwcheck\/master\/Format.txt<\/a><\/p>\n\n\n\n<p>This post is following up from <a href=\"https:\/\/cml-a.com\/content\/2019\/09\/05\/1431\/\">this one<\/a> where I posted the editor, where someone asked about the information that the editor uses<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an explanation of the formats of the password used in the game. I found this information by trying different passwords and seeing what is accepted by the game and what the effects were. Since this process didn&#8217;t involve a debugger it could have been done on the console, but using an emulator sped [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[94,150,152,176],"class_list":["post-2052","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-lord-of-the-rings","tag-retro","tag-reverse-engineering","tag-snes"],"_links":{"self":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/2052","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/comments?post=2052"}],"version-history":[{"count":0,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/posts\/2052\/revisions"}],"wp:attachment":[{"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/media?parent=2052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/categories?post=2052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cml-a.com\/content\/wp-json\/wp\/v2\/tags?post=2052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}