From New Scientist #2932, 31st August 2013 [link] [link]
Kathryn and her school friends have been using a Lorenz-type code to pass covert messages to each other. Each letter is expressed as a five-digit binary number such that A = 1 = 00001, M = 13 = 01101 and so on, but other symbols are represented by 00000 and by 11011 upwards. A fixed letter, say M, is chosen as a “coder”, known only to the sender and receiver. To transmit a letter, say D, it is added to the coder by the “exclusive-NOR” rule:
1 + 1 = 1,
1 + 0 = 0,
0 + 1 = 0,
0 + 0 = 1.
So, for example, D + M = 00100 + 01101 = 10110 = V. When the sent letter V is added by the recipient to the coder M, the original letter reappears: 10110 + 01101 = 00100.
She has sent her name to her friends as seven letters. KATHRYN and its coded version together consist of 14 different letters, so what was the coded version?
[enigma1764]
This Python program runs in 32ms.
Solution: The coded version of KATHRYN is PZOSIBU.
And here’s a different approach. Instead of considering each coding key letter and looking at what the encoded message is, it considers each letter of the plaintext and eliminates coding letters that won’t work for that letter. So it only needs to encode 47 letters rather than 26×7 = 182 letters (not that it makes much difference on a problem of this size).