public Rotor(Rotor rotor)
 {
     for (int i = 0; i < rotor.offsets.Count; i++)
     {
         offsets.Add(rotor.offsets[i]);
     }
 }
 public Form1()
 {
     InitializeComponent();
     //Change rotor offsets (addition paths) here
     //Note: Paths list must be given by how much the digit increases.
     //      If the digit decreases in path, create list with other value in this pair list:
     //      (0,0), (1,9), (2,8), (3,7), (4,6), (5,5)
     rotors[0] = new Rotor(new List <int>()
     {
         1, 2, 4, 7, 1, 9, 2, 0, 1, 3
     }, 0);
     rotors[1] = new Rotor(new List <int>()
     {
         0, 2, 3, 9, 2, 4, 5, 7, 0, 8
     }, 0);
     rotors[2] = new Rotor(new List <int>()
     {
         5, 8, 9, 4, 9, 3, 4, 5, 6, 7
     }, 0);
     rotors[3] = new Rotor(new List <int>()
     {
         1, 5, 3, 9, 5, 5, 1, 7, 5, 9
     }, 0);
     reflector = new Reflector(new List <int>()
     {
         3, 6, 8, 0, 5, 4, 1, 9, 2, 7
     });
 }
 //Rotates given rotor and checks for cases below
 void Rotate(Rotor rotor)
 {
     rotor.Rotate();
     //Rotates to 0 if current position = 10
     if (rotor.currentPosition == rotor.offsets.Count)
     {
         rotor.currentPosition = 0;
     }
     //Rotates middle after full rotation of right
     if (rotor.currentPosition == rotor.startingPosition && rotor == right)
     {
         Rotate(middle);
     }
     //Rotates left after full rotation of middle
     else if (rotor.currentPosition == rotor.startingPosition && rotor == middle)
     {
         Rotate(left);
     }
 }
        private void TextBox_Input_TextChanged(object sender, EventArgs e)
        {
            //Creates machine object
            Rotor     left      = new Rotor(CheckBox_Left1.Checked ? rotors[0] : CheckBox_Left2.Checked ? rotors[1] : CheckBox_Left3.Checked ? rotors[2] : rotors[3]);
            Rotor     middle    = new Rotor(CheckBox_Middle1.Checked ? rotors[0] : CheckBox_Middle2.Checked ? rotors[1] : CheckBox_Middle3.Checked ? rotors[2] : rotors[3]);
            Rotor     right     = new Rotor(CheckBox_Right1.Checked ? rotors[0] : CheckBox_Right2.Checked ? rotors[1] : CheckBox_Right3.Checked ? rotors[2] : rotors[3]);
            Reflector reflector = new Reflector(new List <int>()
            {
                3, 6, 8, 0, 5, 4, 1, 9, 2, 7
            });

            machine = new Machine(left, int.Parse(TextBox_Left_Starting_Position.Text), middle, int.Parse(TextBox_Middle_Starting_Position.Text), right, int.Parse(TextBox_Right_Starting_Position.Text), reflector);

            //Clears and fills output textbox
            TextBox_Output.Text = "";
            foreach (char c in TextBox_Input.Text)
            {
                TextBox_Output.Text += machine.InputDigitToOutput(int.Parse(c.ToString()));
            }
        }
 public Machine(Rotor left, int leftStartingPosition, Rotor middle, int middleStartingPosition, Rotor right, int rightStartingPosition, Reflector reflector)
 {
     this.left = left;
     for (int i = 0; i < leftStartingPosition; i++)
     {
         left.Rotate();
     }
     this.left.startingPosition = leftStartingPosition;
     this.middle = middle;
     for (int i = 0; i < middleStartingPosition; i++)
     {
         middle.Rotate();
     }
     this.middle.startingPosition = middleStartingPosition;
     this.right = right;
     for (int i = 0; i < rightStartingPosition; i++)
     {
         right.Rotate();
     }
     this.right.startingPosition = rightStartingPosition;
     this.reflector = reflector;
 }