Grid Cipher (sometimes also called a grid code) is very simple transposition block symmetric encryption algorithm. It is not usable for any serious cryptography nowadays, but still can be used for games and entertainment.
Traditionally, the grids are created by hand by cutting them from paper. But this process is tedious and prone to errors. So I automated it using 3D printer.
This SCAD file will randomly generate a valid cipher grid each time it's rendered. See variables in source code for customization options. For your convenience, there are several pre-generated grids available for download, if you don't have OpenSCAD installed.
I recommend that you print this model three layers tall. The default settings are for 3 x 0.2 = 0.6 mm height.
How To Encrypt
- Place the grid on paper and remember its orientation. Use the smooth/rough side difference and the round keying hole to note the position.
- Write letters of your message to the square holes.
- When you fill in all holes, spin the grid 90° and continue writing.
- You have to write message which is exactly 100 characters long (for 10x10 grid). If your message is shorter, pad the rest with gibberish. If longer, continue writing another square.
How To Decrypt
- Obtain the same grid that was used for encryption.
- Place it over the encrypted text in the same orientation as when encrypted.
- Read letters showing trough holes.
- Spin the grid 90° and continue reading.
8x8 grid layout scheme
The design of the cipher grid is simple, see the scheme above. The grid is divided into four quadrants. The cells are numbered (see the numbers as index for row and column, ie. "23" in the top right quadrant is row 2, column 3). When the grid is rotated by 90°, hole made in the cell will move to cell with the same number in the next quadrant.
The algorithm to create the code grids is therefore simple: for each position (from "11" to "44" in the picture above) select randomly a quadrant where the hole will be placed. In the code, there are two loops for
iy (as in index x and index y) variables and the
cy (center x/y variables are determined to compute center of the hole, relative to the quadrant). The
iq variable, which determines quadrant, is selected randomly, as is therefore the real placement of the hole.
The outermost cell ("44" in the scheme above) is given a bit of special treatment. I need to place the keying hole (which will allow to note the grid rotation) somewhere. I put it into top right corner of the grid (quandrant 0). However, if the last cell hole is placed in Q0, the key hole is moved to Q2.