[Community Puzzle] Straddling Checkerboard Cryptography

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

I noticed something when playing around with my own code. I’ll explain by example.

Consider the following board:

  0 1 2 3 4 5 6 7 8 9
0 A   B   C D E F G H
1 I J K L M N O P Q R
2 / . S T U V W X Y Z

key = 1

plaintext = A
ciphertext (doesn’t exist)

When/if the last message character keys to one of the blanks, there is no next message character to combine with it, so the last character is lost. I know no one uses this cipher in real life, but it might be worth adding a note to the description.

The easiest solution would probably be to select a key that doesn’t cause a problem with the last character. Alternatively, a program could append a “/” automatically as the last character. It should drop on decryption. (I’m not asking for the puzzle to be changed.)

EDIT: A more elegant solution (I think)

Add a space to the end of the string to be encrypted. If you need a digit, you have it. If you don’t need it, you can discard it when you get to it. Using the example above (with _ for space):

Encrypt: A_ (which needs an additional character)
 A _
 0 1
 1 1 (key)
 1 2
 ^   (blank as next to last char, use last char)
   K <= ciphertext

Decrypt: K
 K
 1 2
 1 1 (key)
 0 1
   ^ (blank as last char, discard)
 A   <= plaintext

Encrypt: C_ (which doesn't need an additional char, but we don't know that yet)
 C  _
 4  1
 1  1 (key)
 5  2
      (no blank as next to last char, discard last char)
 D    <= ciphertext