Saturday, 22 February 2014

Enigma variations

I've been keeping this one under wraps until now as it was a surprise prop in a game some friends were running and playing. Now the game is over I can post about it.

Back in November I found out Elina was playing a Spy and Bletchley Park codebreaker in a WWII/Film Noir themed freeform game. Thinking it might add to the game I contacted the main GM who I know well and offered to build an Enigma machine prop.

At that point I had no idea what it would be or how functional but she jumped at the idea and started to think of ways to add it into the plot. So that was me committed then. :-)

What we have here is a pastiche of the famous German WWII cipher machine, the Enigma. While it is the same size as the original and keeps the spirit of the thing it is not meant to be an exact replica. It's all done with a microcontroller and LEDs for a start. It has five rotors rather than the original three or four and no plugboard. The five rotors were a plot point so I was glad I didn't start building the three rotor one I had in mind at the start.

It is fully functional and uses the original Enigma algorithm to encode/decode messages.

Setting the encryption key is done by turning the rotors and the rotor positions are displayed on 5x7 LED matrices immediately below them.

The keyboard is pretty faithful, made out of a set of keys salvaged from a vintage typewriter, a bunch of brass tube and 27 momentary switches. I've used the QWERTY layout rather than the original QWERTZ as I'm English and it was for an English game.

A degree of obsession with symmetry lead me to add a 27th key, originally thinking it could be a space bar, before realising the algorithm only works with even numbers of characters. So right now it does nothing.

The 27 lamps which show the encoded message are pretty faithful too, only I've used warm white LEDs.

There are then a few indicators and buttons to make it easy to use. This
is a prop to be used in game by everyday people to send secret messages so it had to be fairly simple. They were there to play a game not learn how to use a device from military history. The buttons allow you to play back the plaintext you've typed to check for typos and also the encoded/decoded output so you can write it down easily.

The original had a kind of wrinkle finish paint on the metal covers. This is all made from plywood but I painted the relevant buts with some textured 'weathered iron' paint, which has quite nicely aped the look.

At the heart of it is an Arduino Mega 2560 microcontroller clone and a whole load of hand soldered loom. The keyboard and lamp matrix were hand done and I use the sea of GPIO pins on the big Arduino to multiplex them directly without extra components. When a Mega clone is only £15 why mess around with a smaller one and add extra components to debug? My coding is better than my soldering and that's not saying much.
The rotor movements are read with 'gray code' rotary encoders so they can move through 360 degrees and the matrices driven by MAX7219 driver chips. As you turn the rotors or they advance while typing the letters displayed on the matrices 'scroll' up and down to provide the illusion of a physical machine. It's not the smartest illusion but it works nicely.

The five MAX7219 drivers are mounted on little boards right below each matrix and daisy-chained together. I had a few problems with interference causing the displays to malfunction until I carefully tidied all the wiring up and shortened the data lines.

There are four AA batteries inside so it's portable and can also be run by connecting a USB PSU the to the Arduino USB port. I left the hole in the side of the box for the USB port as it needs to be there for programming anyway. When the batteries need changing you can get to them by removing a small metal cover in the side, I didn't want it so the whole thing had to be ripped open.

If the machine is left untouched for a 15 minutes all the lights and displays shut down to save the batteries and it needs power-cycling to wake it up again.

I hand-rolled all the code, stealing liberally from the Internet for the rotary encoders and MAX7219 without actually using any pre-made libraries. I even made my own 5x7 font for the matrices.

As a bit of added help in the game I chopped the code right down and made a standalone Arduino in a box that takes input from the serial console and encodes/decodes stuff. This is so the game GMs can code/decode messages to pass to/from the players without having to go and use the main machine. A less lazy soul would have ported the code to another environment and maybe written a small app that would run directly on a phone or PC. However I was literally coding this the night before the game and needed it done in an hour. I had the spare Arduino anyway and it can be re-used after the game.

It went down very well in the game and I'm proud of how it's worked out even if some of the woodwork is a bit shonky. I'm an IT guy not a cabinet maker and I scratch built it from the carcass of some 70s plywood furniture I'd knocked to pieces. You can do wonders with hot glue and filler.

2 comments:

  1. I am sad that I never actually got to see the actual machine even though my character managed to steal it in a suitcase literally in the last minutes she was in game. If I could see it at a subsequent occasion we are both attending, I would be over the moon! - Nickey

    ReplyDelete
  2. Talking about particularly of phrase difference by using allegory and proverbs -which at periods outcome in enigmas- in his guide On Copia, Erasmus says: "For factors should not be published in such a way that everyone is aware of everything, but so that they have no choice but to examine factors, and understand." We often study that quality, conciseness, terseness, should be what excellent authors endeavor for. Having seen these admonitions many periods, Erasmus' remark: "Things should not be published in such a way that everyone is aware of everything." What he intended was: create clearly but let something for you to take away and consider. crossword puzzle

    ReplyDelete