Introduction
JN-25 was the Imperial Japanese Navy's main operational code during WWII, and breaking it gave the US the intelligence edge that produced victory at Midway in June 1942. Unlike a pure cipher, JN-25 was a codebook system: 5-digit numbers represented words and phrases, and an additive table masked those numbers before transmission. This tool demonstrates both layers in your browser. Type a message, watch each word map to a 5-digit code, then see the additive key combine with the code digit by digit modulo 10. The step trace shows the full encode or decode path. Nothing leaves your device.
What this tool does
- Encodes plaintext into 5-digit JN-25 code groups using a built-in codebook of 320 common naval terms, then encrypts each group with an additive key (digit-by-digit addition modulo 10)
- Decodes 5-digit cipher groups by subtracting the additive key (modulo 10) and looking up the resulting plain code in the codebook
- Supports a custom additive key of any number of 5-digit groups, cycling through the key as needed for longer messages
- Displays a step-by-step trace showing each word, its codebook value, the additive group applied, and the resulting cipher group (or the reverse for decoding)
- Provides a searchable codebook panel where you can filter entries by term or code number
- Flags words not found in the codebook and codes not found during decoding, so you can see exactly where the process breaks down
How this tool works
The tool has two modes. In Encode mode, it splits your input into words, strips punctuation, and looks up each word in the codebook. The codebook maps 320 common naval terms (ships, ranks, operations, locations, weapons, and more) to deterministic 5-digit codes. For each found word, the tool takes the next 5-digit additive group from your key (cycling back to the start if the key is shorter than the message) and adds it to the code digit by digit modulo 10. The result is the cipher group that would be transmitted.
In Decode mode, the tool splits your input into 5-digit groups, subtracts the additive key digit by digit modulo 10 from each group, and looks up the resulting plain code in the codebook. If the plain code matches an entry, the tool outputs the corresponding term. If it does not match, the tool flags the group as unknown, which is exactly what real codebreakers encountered when the Japanese changed the codebook or the additive tables.
The step trace shows the full pipeline for each word or group. In Encode mode, each row shows the word, its code, the additive applied, and the cipher group. In Decode mode, each row shows the cipher group, the additive subtracted, the plain code, and the decoded term. The codebook panel below the trace is searchable: type a term or a code number to filter the list.
The preset additive key is a sequence of 10 five-digit groups. You can replace it with any number of 5-digit groups separated by spaces. The tool validates that each group is exactly 5 digits and ignores invalid entries. The codebook is a simplified educational set of 320 entries. The real JN-25 codebook had approximately 30,000 entries and was supplemented by separate additive tables that were changed periodically.
How the JN-25 code works
JN-25 was a superenciphered code, which means it combined two layers: a codebook that replaced words with 5-digit numbers, and an additive cipher that masked those numbers. The codebook was the first layer. Each entry mapped a word or phrase (such as AIRCRAFT or PEARL HARBOR) to a 5-digit number. The Japanese distributed codebooks to their naval units and changed them periodically throughout the war.
The additive layer was the second line of defense. After looking up the code for each word, the operator added a 5-digit additive group from a separate additive table, digit by digit modulo 10. For example, if the code was 12345 and the additive was 67890, the cipher group would be (1+6)(2+7)(3+8)(4+9)(5+0) mod 10 = 79134. The recipient subtracted the additive to recover the plain code, then looked it up in the codebook. The additive tables were changed regularly, forcing the American codebreakers to reconstruct each new table from scratch.
Commander Joseph Rochefort led the cryptanalytic effort at Station HYPO in Pearl Harbor. Elliot Carlson describes this work in Joe Rochefort's War (2011), explaining how Rochefort's team combined traffic analysis, partial decrypts, and educated guessing to reconstruct JN-25 additive tables. Craig Symonds covers the operational impact in The Battle of Midway (2011), showing how JN-25 decrypts revealed the Japanese plan to attack Midway in June 1942.
The breakthrough at Midway was not a full break of JN-25. Rochefort's team could read enough fragments to determine the target (AF, which they confirmed was Midway by a clever r involving a freshwater report) and the date of the attack. Admiral Nimitz used this intelligence to position the US fleet northeast of Midway, where it ambushed the Japanese carrier force on June 4, 1942. The Purple machine carried Japanese diplomatic traffic, while JN-25 carried the naval operational messages that directly shaped the Pacific war. The Enigma Machine and SIGABA were rotor machines used by other powers, and the Book Cipher tool demonstrates a related codebook concept without the additive layer.
How to use this tool
- Choose a mode: Encode (plaintext to 5-digit cipher groups) or Decode (5-digit cipher groups to plaintext)
- Enter an additive key consisting of 5-digit groups separated by spaces, or click Load Preset to use the default key
- In Encode mode, type your message as words separated by spaces. Each word is looked up in the 320-entry codebook
- In Decode mode, type 5-digit groups separated by spaces. Each group is subtracted from the additive key and looked up in the codebook
- Read the output in the result field. Check the step trace to see each word's code, the additive applied, and the resulting cipher group
- Use the codebook filter to search for specific terms or codes, and check the errors panel for words or groups that could not be processed
Real-world examples
Encoding a naval operations message
Input: ATTACK PEARL HARBOR with the preset additive key. The tool looks up ATTACK in the codebook (finding its 5-digit code), takes the first additive group 63198, and adds digit by digit modulo 10 to produce the cipher group. It repeats for PEARL and HARBOR with the next additive groups. The output is three 5-digit groups. A history student can compare this two-layer process with the Book Cipher tool, which uses page and line numbers instead of a numeric codebook plus additive.
Decoding with the correct additive key
Take the three cipher groups from the first example, switch to Decode mode, and paste them with the same additive key. The tool subtracts each additive group digit by digit modulo 10, recovers the plain codes, and looks them up in the codebook. The output is ATTACK PEARL HARBOR. This demonstrates the full round-trip: encode, transmit (conceptually), and decode with the same key and codebook.
Handling words not in the codebook
Type a message containing a word that is not in the 320-entry codebook, such as HELLO WORLD. The tool flags HELLO and WORLD as not found and skips them in the output. The errors panel lists each missing word. This mirrors the real JN-25 experience: codebreakers frequently encountered code groups they could not yet translate, either because the word was not in their reconstructed codebook or because the additive table had changed.
Demonstrating the additive layer's effect
Encode the word AIRCRAFT with two different additive keys. With the first additive group 63198, the cipher group is one value. With a different group, say 11111, the cipher group is completely different. This shows why the additive layer mattered: even if an attacker captured the codebook, they could not read messages without the current additive table. The Japanese changed these tables periodically, which is why Rochefort's team had to reconstruct each new table before they could resume reading traffic.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Book cipher | Low (page and line numbers) | Espionage, pre-computer era |
| JN-25 (simplified) | Medium (codebook plus additive modulo 10) | WWII Japanese naval operations |
| Purple (simplified) | High (stepping switches) | WWII Japanese diplomatic traffic |
| Enigma (3-rotor) | High (rotor-based) | WWII German military communications |
| SIGABA | Very high (irregular stepping) | WWII US high-level communications |
| Modern AES-256 | Very high (14 rounds, 256-bit key) | Secure digital encryption |
Limitations or considerations
This tool uses a simplified codebook of 320 entries. The real JN-25 codebook had approximately 30,000 entries covering thousands of naval terms, ship names, and operational phrases. Messages containing words outside the 320-entry set will be flagged as errors, which limits the tool to demonstration purposes.
The additive key in this tool is a simple sequence of 5-digit groups that cycles through the message. The real JN-25 used complex additive tables that were changed periodically, and the additive groups were selected based on the message date and a starting position indicator. This tool does not model the date-based selection or the starting position system.
JN-25 is completely obsolete and insecure by any modern measure. It was broken by hand and electromechanical methods in the 1940s. The additive layer (digit-by-digit addition modulo 10) provides no real security once the codebook is known. Never use this tool for real encryption. For modern security needs, use the AES Encrypt / Decrypt tool or another NIST-approved algorithm.
Frequently asked questions
What is the difference between a code and a cipher?
A cipher replaces or transforms individual letters or groups of letters according to an algorithm. A code replaces whole words or phrases with symbols (in JN-25, 5-digit numbers). JN-25 was a superenciphered code, meaning it used both: the codebook replaced words with numbers, and the additive cipher masked those numbers. This two-layer design was common in WWII naval codes because it reduced transmission length while adding a layer of encryption.
How did breaking JN-25 lead to the victory at Midway?
Rochefort's team at Station HYPO read enough JN-25 fragments to determine that the Japanese planned to attack a location coded as AF in early June 1942. They confirmed AF was Midway by having Midway send a plaintext message about a freshwater shortage, which the Japanese then reported in JN-25 as an AF freshwater problem. Admiral Nimitz used this intelligence to position the US fleet to ambush the Japanese carriers on June 4, 1942, sinking four carriers and changing the course of the Pacific war.
Why did the additive layer use modulo 10 arithmetic?
The codebook produced 5-digit decimal numbers, so the additive layer operated on decimal digits (0-9) rather than binary. Adding two digits modulo 10 means the result is always a single digit (for example, 7 + 8 = 15, and 15 mod 10 = 5). This kept the cipher groups as valid 5-digit numbers that could be transmitted by telegraph and read by standard equipment. Subtraction modulo 10 reverses the process cleanly.
How often did the Japanese change the JN-25 additive tables?
The Japanese changed the additive tables periodically, typically every few months, and also updated the codebook itself less frequently. Each change forced the American codebreakers to reconstruct the new tables from scratch using traffic analysis and partial decrypts. This is why the US could read some JN-25 traffic but not all of it at any given time, and why the intelligence picture at Midway was incomplete but sufficient.
Was JN-25 the same as the Japanese diplomatic Purple cipher?
No. JN-25 was a naval operational code used by the Imperial Japanese Navy for tactical and strategic communications. Purple was a diplomatic cipher machine used by the Japanese Foreign Ministry for embassy traffic. They were completely different systems with different designs, different code names (JN-25 versus Magic for Purple-derived intelligence), and different cryptanalytic teams working on them. The Purple tool demonstrates the diplomatic machine.
Conclusion
JN-25 is the code that shaped the Pacific war. Rochefort's team at Station HYPO broke enough of it to give Nimitz the intelligence he needed at Midway. This tool lets you watch the two-layer process (codebook plus additive) in action, which is the core of how JN-25 worked and how it was attacked. To compare with other WWII systems, try the Purple, Enigma Machine, SIGABA, and Book Cipher tools. For modern encryption, use the AES Encrypt / Decrypt tool instead.