Introduction
American prisoners of war in North Vietnam had no radios, no paper, and no way to write messages that guards would not find. They communicated by tapping on walls. The tap code, based on a 5x5 Polybius grid, let POWs spell out words through solid concrete. Commander Jeremiah Denton famously blinked T-O-R-T-U-R-E in Morse code during a 1966 propaganda interview, but the tap code was the everyday workhorse inside the cells. Vice Admiral James Stockdale described the system in his 1984 memoir "In Love and War," noting that prisoners spent months learning to send and receive taps with their knuckles. This tool listens to your microphone, detects taps using the Web Audio API, and decodes them into text in real time. It also accepts manual input if you do not have a microphone.
What this tool does
- Detects taps from your microphone in real time using the Web Audio API, measuring amplitude spikes against an adjustable sensitivity threshold
- Maps detected taps to the standard 5x5 Polybius grid (C and K share cell 1,3), producing decoded text as you tap
- Distinguishes between taps within the same letter (under 0.6 seconds apart), gaps that start a new letter (0.6 to 2 seconds), and gaps that start a new word (2 to 3.5 seconds)
- Accepts manual input in the format '1 2, 2 3, 3 1' where pairs are separated by commas and words by semicolons, for users without a microphone or for testing
- Displays the live tap pattern as row-column pairs (e.g. '2,3 1,5 3,4') alongside the decoded text, so you can verify detection accuracy
- Runs entirely in your browser. Audio from your microphone is processed locally and never sent to any server
How this tool works
The tool uses the browser's Web Audio API to capture microphone input through getUserMedia. An AnalyserNode with an FFT size of 2048 samples reads the time-domain waveform at each animation frame. The tool computes the peak amplitude deviation from the center value (128 in the 0-255 byte range) and compares it against a threshold derived from the sensitivity slider. When the amplitude crosses the threshold from below, the tool registers a tap.
The detection logic tracks tap timing to group taps into letters. The first group of taps determines the row number, the second group determines the column number. For example, two taps followed by three taps produces row 2, column 3, which maps to the letter H in the Polybius grid. Gaps between taps are classified by duration: under 600 milliseconds means the same letter continues, 600 to 2000 milliseconds means a new letter begins, and 2000 to 3500 milliseconds means a new word begins.
The manual input mode parses sequences like '2 3, 1 5, 3 4' by splitting on commas for letter pairs and semicolons or newlines for word boundaries. Each pair of numbers is looked up in the 5x5 grid. This mode works without microphone access and is useful for verifying tap patterns from historical records or training exercises.
How the tap code works (5x5 Polybius grid)
The tap code is a Polybius square cipher adapted for auditory communication. The 26-letter alphabet is arranged in a 5x5 grid, with C and K combined into a single cell (row 1, column 3) to fit 25 positions. Each letter is represented by two numbers: its row and its column. The letter H, for instance, is at row 2, column 3, so it is sent as two taps followed by three taps.
The system has roots in ancient Greek fire-signaling methods described by Polybius in his "Histories" (Book X), where a five-by-five grid of letters was paired with torch positions. The modern tap code was adapted by American military personnel for use in prisoner-of-war camps. Vice Admiral James Stockdale, the senior naval officer at the Hanoi Hilton prison camp, described in "In Love and War" (written with his wife Sybil Stockdale, published 1984 by the Naval Institute Press) how prisoners used the code to communicate between cells. The POWs called it the "smoke code" or "tap code" and built an entire communication network with it, including teaching new arrivals through wall taps.
Commander Jeremiah Denton, shot down in 1965, used blinking rather than tapping to send a message during a Japanese-produced propaganda film. He blinked the letters T-O-R-T-U-R-E in Morse code, not tap code, to signal that POWs were being tortured. The event is documented in the U.S. Navy's historical records and in Denton's 1976 book "When Hell Was in Session." The tap code itself is simpler than Morse code because it requires only two timing categories (tap and gap) rather than three (dot, dash, and gap), making it easier to teach and to send through walls.
For the text-only version of this cipher, see the Tap Code tool. The Two Tap Code is a variant that uses a different grid arrangement. For audio-based signaling with a longer history, see the Morse Code translator.
How to use this tool
- Click Start Recording and allow microphone access when the browser prompts you. The tool begins listening for amplitude spikes.
- Adjust the sensitivity slider if needed. Higher values detect quieter taps but may pick up background noise. Lower values require louder knocks.
- Tap or knock near your microphone. The first group of taps sets the row (1 to 5), then a brief pause, then the second group sets the column (1 to 5).
- Watch the live tap display to verify detection. It shows the current row-column pair as taps accumulate, then the completed pattern once a letter is finalized.
- The decoded text appears automatically. Gaps of 2 to 3.5 seconds insert a space between words. Gaps over 3.5 seconds finalize the current word.
- To use manual input instead, type tap pairs in the input field (e.g. '2 3, 1 5, 3 4' for 'HE'). Separate letters with commas and words with semicolons.
- Click Clear to reset the detection state and start a new message.
Real-world examples
Spelling HELLO with taps
The word HELLO breaks down as: H = row 2, col 3 (two taps, pause, three taps); E = row 1, col 5 (one tap, pause, five taps); L = row 3, col 4 (three taps, pause, four taps); L = same; O = row 3, col 5 (three taps, pause, five taps). The full pattern is "2 3, 1 5, 3 4, 3 4, 3 5". In manual mode, enter "2 3, 1 5, 3 4, 3 4, 3 5" and the tool outputs "HELLO".
Decoding a POW-style wall message
A history student simulates a prison cell scenario by knocking on a desk near their laptop microphone. They set sensitivity to 70% and tap out "SOS" (S = 4,3; O = 3,5; S = 4,3). The tool detects the amplitude spikes, groups them by timing, and displays "SOS" in the decoded text field. The pattern field shows "4,3 3,5 4,3" confirming the row-column mapping.
Handling the C/K ambiguity
The word "KING" contains a K, which shares cell 1,3 with C. The tap sequence is K = 1,3; I = 2,4; N = 3,3; G = 2,2. The decoded output shows "C/KING" because the grid cell contains "C/K". The recipient must use context to determine whether the letter is C or K. In practice, POWs resolved this ambiguity from the surrounding word, since English rarely allows both letters in the same position.
Testing with manual input
A user without a microphone enters "1 2, 1 5; 2 3, 1 5, 3 4, 3 4, 3 5" in the input field. The semicolon separates two words. The tool parses the pairs and outputs "AE HELLO". This mode is useful for checking tap patterns from historical transcripts or for classroom exercises where students decode written tap sequences before trying audio detection.
Comparison with similar methods
| Method | Complexity | Typical use |
|---|---|---|
| Tap code (5x5 grid) | 2 taps per letter, 25 symbols | POW communication, no equipment needed |
| Morse code | Variable-length dots and dashes, 36+ symbols | Radio telegraphy, emergency signaling |
| Two tap code | 2 taps per letter, modified grid | Variant grid arrangement for different cell mapping |
| Polybius square (visual) | 2-digit number per letter | Classical signaling, educational exercises |
| NATO phonetic alphabet | One word per letter, spoken | Voice radio communication, spelling over noise |
Limitations or considerations
The audio detection relies on amplitude thresholding, not frequency analysis. It cannot distinguish between a deliberate tap and any loud sound (a door slam, a cough, a dropped object). In noisy environments, false detections are common. Adjust the sensitivity slider to filter out background sounds, but this also makes the tool less responsive to quiet taps.
The timing thresholds (600ms for same-letter, 2000ms for new-letter, 3500ms for new-word) are fixed. If you tap faster or slower than these thresholds, letters may merge or split incorrectly. The original POW tap code had no standardized timing; prisoners adapted to their cellmate's rhythm. This tool uses reasonable defaults but cannot match that flexibility.
The 5x5 grid combines C and K into one cell. The decoded output shows "C/K" for that position, requiring human judgment to pick the correct letter. The tool does not attempt automatic disambiguation. For text-only encoding and decoding without these audio limitations, use the Tap Code tool.
Frequently asked questions
Is the tap code the same as Morse code?
No. Morse code uses variable-length sequences of dots and dashes (three timing categories). The tap code uses a 5x5 Polybius grid where each letter is two numbers (row and column), sent as groups of taps. Morse code encodes more characters but requires learning roughly 40 distinct patterns. The tap code requires learning only the grid layout.
Did Vietnam POWs actually use this system?
Yes. Vice Admiral James Stockdale described the tap code in detail in his 1984 memoir 'In Love and War.' Prisoners at the Hanoi Hilton and other camps used it to communicate between cells, teach new arrivals, and coordinate resistance. The system was attributed to Captain Carlyle 'Smitty' Harris, who learned it from a training film and introduced it to his fellow POWs.
Why do C and K share the same cell?
The 5x5 grid has 25 positions, but the English alphabet has 26 letters. One pair must be combined. C and K are merged because they share the same sound in many words, and the combination causes minimal ambiguity in practice. Some versions of the grid combine I and J instead, but the POW standard used C/K.
Can the tool detect taps through a wall?
The tool detects any sound that exceeds the amplitude threshold. If you place your device near a wall and someone taps on the other side loudly enough, the microphone may pick it up. However, the tool is designed for direct taps near the microphone, not for wall-mediated detection. Background noise and wall thickness will affect reliability.
What happens if I tap too fast or too slow?
The tool uses fixed timing thresholds: taps under 600ms apart are grouped into the same letter, gaps of 600 to 2000ms start a new letter, and gaps of 2 to 3.5 seconds start a new word. If you tap faster than 600ms between groups, the tool may merge two letters. If you pause longer than 3.5 seconds, it may insert unwanted word breaks. Practice maintaining a steady rhythm.
Does the microphone audio leave my browser?
No. The Web Audio API processes all audio locally in your browser. The microphone stream is analyzed in real time and discarded. No audio is recorded, stored, or transmitted to any server. The manual input mode does not use the microphone at all.
Conclusion
This tool brings the tap code from prison camp walls into your browser. The audio detection mode shows how amplitude thresholding can turn knocks into text, while the manual mode lets you decode written tap sequences without a microphone. The tap code is a simple but historically significant communication method that required no equipment beyond a surface to knock on. For the text-only version, see the Tap Code tool. For a variant grid, try the Two Tap Code. For the more complex audio signaling system that inspired many code-based communication methods, see the Morse Code translator.