Another useless encryption scheme devised by yours truly. While my last one (pi code) was primarily a substitution cipher, this one transcends all standard classifications; it’s almost like a transposition cipher, but not really. The main idea here is the use of certain numbers in a particular Sudoku grid. The strength (if any) in this method lies in its unexpected nature; it certainly takes quite a leap of the imagination to correctly deduce the method from the ciphertext. Of course, once the method has been discovered, deciphering merely involves solving a Sudoku grid and then figuring out the substitution cipher used, meaning that the key is easy to determine and so this method kind of just looks at Kerckhoffs’s Principle and then keeps walking. But that’s okay, that’s why this is filed under useless. (Editor’s note: This post was indeed originally categorised as “useless”, but my category system recently staged a rebellion and now I no longer have categories like “useless”.)
The first step is to find a Sudoku puzzle. I happened to have a Sudoku game installed, so I just ran that and started a random puzzle, which looked like this:
The (unique) solution to the above puzzle looks like this:
Clearly, each solved grid can be represented by a sequence of 81 numbers. Furthermore, due to the uniqueness of the solution, the initial grid and the solved grid are equivalent in the sense that the initial grid uniquely determines the solved grid. So we represent the initial grid as follows (with 0s standing for spaces):
This results in the following solution grid:
Now, depending on the length of the plaintext, we can choose somewhere between one and five numbers to use as the “holes” in the grid. For example, if we had a plaintext of 45 characters or fewer, we could choose the numbers 1, 2, 5, 6 and 9. Removing those numbers from the grid would leave us with this:
This has an entirely different arrangement of empty spaces than the initial grid. We can represent it using the following string:
We can then use the empty spaces to write our message, and add characters in the rest of the spaces to try and flatten frequencies. A simple substitution cipher should be used as well to prevent the ciphertext from looking too much like a transposition cipher. The alphabetic characters can then be interspersed with the numerals above, with the resulting string separated into chunks of 32 characters (with extra alphabetic characters appended as necessary, since only 81 are needed) so as to superficially resemble MD5 (because that’s just fun).
Optimally, the solutions to the possible Sudoku grids being used should be stored in a dictionary somewhere, so that each grid only has to be solved once. The point of this encryption scheme is to be diabolically tricky but solvable, although perhaps only if you figure out the Sudoku aspect and know a crib or two.
Encoding and decoding a sequence
Let’s say you want to encode:
admiral yamamoto to visit solomon islands eight am
First, remove spaces:
This is 43 characters, so let’s aim for one grid with 5 numbers. This means there will be 2 extra invalid characters and 36 nonsense characters. Since some spaces will be fairly large, it’s a good idea to use a simple substitution cipher as well (or even a less simple one like Vigenère for additional fiendishness). In this case, we’ll use the reverse alphabet cipher:
So the encrypted plaintext becomes
Now put it in the grid:
(The last two characters are the extra invalid characters used to fill up the empty spaces.)
Now replace the remaining numbers with random letters, chosen so as to flatten the letter frequencies as much as possible:
Written as one line, the above grid would look like:
Recall that the original grid looks as follows:
With the numbers used added to the end of the grid, it might look like this:
Now, we randomly combine the two: (split across two lines here due to design considerations)
We could even put in extra characters at the end, since only the first 81 characters will be used:
Here’s how it would look if we split it up into 32-character chunks:
And there you go. Not indecipherable but certainly very misleading. To decipher, first separate the numerals from the alphabetic characters, then write out the first 81 characters within a 9x9 grid. Then fill another 9x9 grid with the first 81 numerals (one digit per box), omitting the zeros, and solve the resulting Sudoku puzzle. Take the remaining (non-zero) digits and highlight the positions in the grid corresponding to those digits. The characters corresponding to the non-highlighted positions can be discarded. Now it only remains to reverse the substitution cipher and insert spaces where necessary.
Implementation in Python
All the relevant code is available in the repository for this website, under _includes/sudokucode. The 3 main files are shown below.
Instead of encrypting the Sudoku puzzle itself, use a standard one. For example, if you and your imaginary recipient both have access to the New York Times, which we will pretend has a daily Sudoku puzzle if it doesn’t actually, then just use that. Then, the only numbers you’d have to send along with the plaintext (and the extra characters) are the hole digits. This means that the key itself (or at least the prelude to the key) does not have to be distributed along with the message, resulting in a somewhat more secure scheme (for a given value of “secure”). This will work as long as you ensure that the Sudoku puzzle that you choose always has a unique solution.