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 8The Code: Rotors

The Code: Rotors
This is a more detailed description of the rotors in the program.  Basically I defined the rotors like this:

const char rI[26] = {'E',
'K',
'M',
'F',
'L',
'G',
'D',
'Q',
'V',
'Z',
'N',
'T',
'O',
'W',
'Y',
'H',
'X',
'U',
'S',
'P',
'A',
'I',
'B',
'R',
'C',
'J'};

const char rII[26] = {'A',
'J',
'D',
'K',
'S',
'I',
'R',
'U',
'X',
'B',
'L',
'H',
'W',
'T',
'M',
'C',
'Q',
'G',
'Z',
'N',
'P',
'Y',
'F',
'V',
'O',
'E'};

char rIII[26] = {'B',
'D',
'F',
'H',
'J',
'L',
'C',
'P',
'R',
'T',
'X',
'V',
'Z',
'N',
'Y',
'E',
'I',
'W',
'G',
'A',
'K',
'M',
'U',
'S',
'Q',
'O'};

You may ask "Why not just define them as a string, this seems like longhand".  In other words why not do it like this:

char rotI[26] = "'EKMFLGDQVZNTOWYHXUSPAIBRCJ"

I'll admit this makes for much longer code, but to me it makes more sense visually to see it down (I can't think of a time I've ever done this before, but with this one I think it works).  Basically since these are rotors (and I was copying the values off a paper Enigma machine) then that's the way I chose to do it.

In addition to defining the reflectors I defined what number each rotor should turn the next rotor on.  In other words, when RI is in position 17, then the rotor to the left should turn.

const int spinRI = 17;
const int spinRII = 5;
const int spinRIII = 22;

Because the rotors can be put in any of the three slots you see in the screen I copy the constant spin values into ints that change anytime a different rotor is put in a slot (r1 is the left most rotor, r2 is the center rotor, r3 is the right most rotor).

int spin_r1 = spinRI;
int spin_r2 = spinRII;
int spin_r3 = spinRIII;

The following variables keep track of what rotor is in what slot.  This is used so you know when you change rotors in a slot what rotor next one will be

int cur_r1 = 1;
int cur_r2 = 2;
int cur_r3 = 3;

I also define the reflector.  Basically what this is saying is if an input comes in at position 3, then it should go back out position 7 for example (since the value in position 3 is 7).  The reflector basically sends the signal back through the rotors in reverse order

int reflector[26] = {24,
17,
20,
7,
16,
18,
11,
3,
15,
23,
13,
6,
14,
10,
12,
8,
4,
1,
5,
25,
2,
22,
21,
9,
0,
19};

These are placeholders for the current rotor array in positions 1, 2, and 3 on the screen
char rotor1[26];
char rotor2[26];
char rotor3[26];

Note: The image in this step is from Wikipedia
« 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