The tap code (sometimes called knock code) is a very simple way to encode text messages on a letter-by-letter basis. The message is transmitted using a series of tap sounds, hence its name. The code has been commonly used by prisoners to communicate with each other, usually by tapping either the metal bars, pipes or the walls inside a cell.
The code is based on a square $$5 \times 5$$ grid in which all letters are written in alphabetic order from top to bottom and from left to right, except for the letter K which is equated to the letter C.
1 | 2 | 3 | 4 | 5 | |
---|---|---|---|---|---|
1 | A | B | C/K | D | E |
2 | F | G | H | I | J |
3 | L | M | N | O | P |
4 | Q | R | S | T | U |
5 | V | W | X | Y | Z |
The listener only needs to discriminate the timing of the taps to isolate letters, since each letter is communicated by tapping two numbers:
the first number designates the row where the letter occurs in the grid (horizontal)
the second number designates the column where the letter occurs in the grid (vertical)
For example, to specify the letter B, one taps once, pauses, and then taps twice. To communicate the word VICTOR, the cipher would be the following (the pause between each number in a pair is smaller than the pause between letters):
V | I | C | T | O | R |
---|---|---|---|---|---|
5, 1 | 2, 4 | 1, 3 | 4, 4 | 3, 4 | 4, 2 |
..... . | .. .... | . ... | .... .... | ... .... | .... .. |
Because of the difficulty and length of time required for specifying a single letter, prisoners often devised abbreviations and acronyms for common items or phrases, such as GN for good night or GBU for god bless you.
By comparison, Morse code1 is harder to send by tapping or banging because it requires the ability either to create taps with a clear and precise rhythm or to produce two different-sounding noises. Morse code also takes longer to learn. Learning the square grid simply requires one to know the alphabet and the short sequence AFLQV (the initial letter of each row).
Communication through tap code is represented as a string (str), with taps represented as dots (.) and pauses between two sequences of taps (both the pause between two numbers representing a letter and the pause between two letters) represented as spaces. Your task:
Write a function encode_letter that takes a letter (str). The function must return a tuple containing the row index (int) and the column index (int) of the cell containing the letter in the square grid used by the tap code. The function must make no distinction between uppercase and lowercase letters.
Write a function decode_letter that takes two integers (int) representing the row index and the column index of a cell in the square grid used by the tap code. The function must return the uppercase letter in the given cell of the grid. The function must assume that the cell on row 1 and column 3 of the grid contains the letter C.
Write a function encode that takes a word (str) that only contains letters. The function must return how this word is communicated using tap code (str). The function must make no distinction between uppercase and lowercase letters.
Write a function decode that takes the communication of a word using tap code (str). The function must return the communicated word (in uppercase letters).
>>> encode_letter('V')
(5, 1)
>>> encode_letter('i')
(2, 4)
>>> encode('VICTOR')
'..... . .. .... . ... .... .... ... .... .... ..'
>>> encode('Charlie')
'. ... .. ... . . .... .. ... . .. .... . .....'
>>> decode_letter(5, 1)
'V'
>>> decode_letter(2, 4)
'I'
>>> decode('..... . .. .... . ... .... .... ... .... .... ..')
'VICTOR'
>>> decode('. ... .. ... . . .... .. ... . .. .... . .....')
'CHARLIE'
United States prisoners of war (POW) during the Vietnam War are most known for having used the tap code. It was introduced in June 1965 by four POWs held in the Hỏa Lò2 prison (better known as Hanoi Hilton): Captain Carlyle "Smitty" Harris, Lieutenant Phillip Butler, Lieutenant Robert Peel, and Lieutenant Commander Robert Shumaker. Harris had heard of the tap code being used by prisoners in World War II and remembered a United States Air Force instructor who had discussed it as well.
In Vietnam, the tap code became a very successful way for otherwise isolated prisoners to communicate. POWs would use the tap code in order to communicate to each other between cells in a way which the guards would be unable to pick up on. They used it to communicate everything from what questions interrogators were asking (in order for everyone to stay consistent with a deceptive story), to who was hurt and needed others to donate meager food rations. It was easy to teach and newly arrived prisoners became fluent in it within a few days. It was even used when prisoners were sitting next to each other but not allowed to talk, by tapping on another's thigh. By overcoming isolation with the tap code, prisoners were said to be able to maintain a chain of command and keep up morale.
Captured by the North Vietnamese in 1965, Navy pilot Jeremiah Denton was forced to participate in a propaganda interview to be broadcast in the United States. Pretending to be oppressed by the television lights, he blinked the word "T-O-R-T-U-R-E" in Morse code — alerting U.S. Naval Intelligence for the first time that American prisoners were being tortured.
In his Investigator's Guide to Steganography3 (2003), Gregory Kipper notes that captured soldiers would sometimes use hand signals to transmit messages during photo ops:
often, these gestures were airbrushed out by the media