3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Kid's Game to Arduino Enigma Machine

Step 7The Code:Overview

The meat of the code is pretty simple.  I have an array for each rotor type, then I just needed to keep track of what rotor was in what slot, and what position the rotor was currently in.  Probably the easiest way to figure out what the code needs to do is to go through the example of this paper enigma machine.  http://mckoss.com/Crypto/Paper%20Enigma.pdf  .  Basically we need to take the input index, look at what letter is in that spot, then figure out what slot that should map to (it's basically the where the letter ends up in a char array of the alphabet and the offset of the rotor).

The code also needs to handle the rotors moving.  The right most rotor moves one spot every time a key is pushed.  The middle rotor moves when the right most rotor hits a certain value (so it will turn 1/26 of the times the right one turns).  The left rotor turns 1/26 of the times the center rotor turns.  To do this I have an int that keeps track of the current position of the rotor and I add one to it when they need to turn.  When they get to 26 I set them back to 0 (it went all the way around the rotor so we're starting again).

To swap out rotors I simply strncpy the rotor constants to the rotor in for the position.

You'll notice I used a lot of example code in my code to do things like play tones, get keypad values, and address the I2C LCD.  I'm a big fan of libraries and example code.
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
8
Followers
5
Author:sketchsk3tch