Enigma Simulation - Internals

Introduction

This documents some of the simulation internals. It is what and sometimes why I did what I did.

Lists

Lists do not contain characters. They contain list indexes which represent characters. When needed they can be converted to a character to display to the user or convert a user's input character to a list index.

Lists are used for character substitutions ciphers. A list index represents an "in" character and the list value at that index represents the "out" character.

A rotor is advanced after a key is pressed. With dictionaries is got very complicated to implement. Lists were simpler.

I think using lists is also more efficient. Perhaps not. I did not perform any tests.

Why lists for rotors, reflector, and plugboard

The encode/decode "circuit" passes through each rotor twice. This means each rotor must encode/decode a character twice. If only one list is used, one direction (right-to-left, left-to-right) must search a list rather than directly convert it.

I played around with using dictionaries and decided it got too complicated. Lists seem more direct. (I could be wrong.)

Why right-to-left rather than left-to-right

In some document I read, when a key is pressed it hits the right rotor first. I kept this convention and reflect it in the data structures. When there is directionality in a list, element 0 is the left rotor, element 1 is the middle rotor, and element 2 is the right rotor. ([left,middle,right])

Why rotors internally have right-to-left and left-to-right lists

Characters (list indexes) are passed thru rotors twice. I use two list for this double pass. I am not sure this is the most efficient way, but this is what I did.

The code could be simplified

I made the code somewhat simple and verbose. I hope it will help the reader better understand what is going on. (Perhaps it just confuses people?)