Processing: How to Code A Wheel Cipher Layout

Thomas Jefferson's Wheel

I’ve been reading Code Breakers by Rudolf Kippenhahn. What hooked me into it was the part about the Wheel Cipher, a device envisioned by Thomas Jefferson in the late 1700’s. You can see Jefferson’s note about the wheel in his very own, genuinely awful handwriting here.

If you, like me, cannot read it, just imagine you have a rolling pin, an axe, and really good aim. You cut the rolling pin into several equal parts—now you have your wheels. Then spend the next week painstakingly etching the letters of the alphabet on each wheel in completely random order. Once that’s done, thread them together with a spindle or some twine, whatever’s handy. Now do the exact same thing to another rolling pin—with the exactly same randomized order as the first—and send that to whoever you wish to communicate with.

Rotate the wheels to create a message. Look a few lines down and copy down the completely random sequence of letters there—that’s your key. You send that to whoever has a wheel exactly like yours, and they can rotate their letters to match it. Presumably, they’ll be able to look a few lines up and see your message.

My first thought at reading about the wheel was it would’ve been a hellish to manufacture back then. Randomizing the alphabet on multiple wheels? If you repeat a letter by accident, it’s no good. Duplicates would throw off the key. You’d have to start over.

But it’d completely throw any frequency distribution analysis. You couldn’t look for the most common letters and work backwards. I’m honestly not sure how (or if) you could go about breaking it from the key alone. It’s entirely possible your only course of action would be to find someone with wheel, conk them over the head, and steal it.

Returning to the point. Manufacturing such a device. Easier with computers, right? You could start off by modelling the wheel in Blender.

Step 1: Create a Circle in Blender

Follow Active Quads UV

You’ll need to extrude the edges to get the actual faces of the wheel. Keep in mind, circles in Blender have 32 edges. There are only 26 letters in the alphabet, but hell, why not throw in some extra characters to make it busier. Even better, right? What if I want to send someone a web address?

I want a space, a period, a colon, a question mark, a backslash, and &. That gets us to 32 characters.

Later on, I might make a more complicated version with a full set of numbers, but for now, I’m leaving them out.

Step 2: Switch to Processing

UV Layout

Alright—the UV map I exported from Blender is 90 pixels by 995 pixels. I know there’s a way to do this in Scheme, but I’m doing it in Processing. I’m not saying I did this particularly well in Processing, but this is more of a first draft.

Processing syntax to add text looks like this:

CharactersToDisplay, x-position, y-position)

Our x position on the grid will be constant at 45 pixels. The y position will need to be worked into a loop to get the spacing right. 995 divided by 32 is approximately 31.1, so we’ll just have to add that amount with each iteration. Since we want to start half-way down the first face, we can divide 31.1 by 2 and set our x variable to start at 15.55.

Remember, Processing syntax to assign global variables is:

datatype variablename = value;
float y = 15.55

Because arrays are beautiful things, I thought I’d be plugging the alphabet into one and just looping through it.The array itself would just look like this:

String[] abc = {“a”,”b”,”c”… and so on};

But you need to randomize the order first.

Google told me my best bet was probably going to be shuffle(). Shuffle is for lists, so you’ll need to use .append to loop through the existing array to push all the values into a StringList. Once that’s done, .get will pull them through a loop. And that’s pretty much it. Just plug in the desired file path for your UV layout at the bottom.

Here’s the script altogether:

float x = 45;
float y = 15.55;
String [] abc = {" ",".",":","?","/","&","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
StringList alphabet;

void setup(){
alphabet = new StringList();
for (int i = 0; i < 32; i++){
size(90, 995);

void draw(){
for (int i=0; i<32; i++) {
text(alphabet.get(i),x, y);
y = y+ 31.09;

There are a couple of funny things that I’m hoping to fix. I want Processing to randomize a specific number of UV layouts. To make my first wheel, I had to run the script several times and stop it after the PNG appeared in the specified file. Always nice to have built-in glitches to address in Version 2.0.

Step 3: Adjust the Border in Gimp/Photoshop

Gimp Export

This is the step where you can customize the color and stuff. Go nuts.

Then plug that the randomized PNGs into the texture nodes, and voilà. Jefferson’s Cipher. Version 1.0.

Jefferson V1


6 Replies to “Processing: How to Code A Wheel Cipher Layout”

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: