A keyboard shift error happens when every character is entered next to its intended key on a keyboard layout. Recognizing that pattern can recover an otherwise unreadable message. section 9.11
To decode a suspected keyboard shift error:
- Identify the likely keyboard layout, such as QWERTY. section 9.11
- Shift each character consistently toward the adjacent key, testing the direction that produces recognizable words. section 9.11
- Check the resulting phrase for meaningful language rather than accepting a merely plausible translation. section 9.11
A scrambled question
The string “ejsy fprd yjod ,rddshr dsu?” becomes “what does this message say?” when each character is shifted to the appropriate adjacent QWERTY key. section 9.11
# Decoding the scrambled message by shifting each character to the left on a QWERTY keyboard
def decode_shifted_message(message):
# QWERTY keyboard layout
keyboard_layout = {
'q': '1', 'w': '2', 'e': '3', 'r': '4', 't': '5', 'y': '6', 'u': '7', 'i': '8', 'o': '9', 'p': '0',
'a': 'z', 's': 'x', 'd': 'c', 'f': 'v', 'g': 'b', 'h': 'n', 'j': 'm', 'k': ',', 'l': '.', ':': '/',
'z': '`', 'x': 'q', 'c': 'w', 'v': 'e', 'b': 'r', 'n': 't', 'm': 'y', ',': 'u', '.': 'i', '/': 'o',
'1': '`', '2': '1', '3': '2', '4': '3', '5': '4', '6': '5', '7': '6', '8': '7', '9': '8', '0': '9',
'-': '0', '=': '-', '`': '=', '[': 'p', ']': '[', '\\': ']', ';': 'k', “'”: 'l', ',': 'm', '.': ',',
'/': '.', ' ': ' '
}
decoded_message = ""
for char in message:
if char in keyboard_layout:
decoded_message += keyboard_layout[char]
else:
decoded_message += char
return decoded_message
# Decoding the given message
decoded_message = decode_shifted_message("ejsy fprd yjod ,rddshr dsu?")
decoded_message
A Python listing shows how a lookup table can translate each input character into its neighboring-key character and rebuild the decoded message. section 9.11
