//sets the machine public Machine(Rotor first, int leftStartingPosition, Rotor middle, int middleStartingPosition, Rotor last, int rightStartingPosition, Reflector reflector) { this.first = first; for (int i = 0; i < leftStartingPosition; i++) { first.Rotate(); } this.first.originalPosition = leftStartingPosition; this.middle = middle; for (int i = 0; i < middleStartingPosition; i++) { middle.Rotate(); } this.middle.originalPosition = middleStartingPosition; this.last = last; for (int i = 0; i < rightStartingPosition; i++) { last.Rotate(); } this.last.originalPosition = rightStartingPosition; this.reflector = reflector; }
private void TextBox_Input_TextChanged(object sender, EventArgs e) { Rotor first = new Rotor(First_1.Checked ? rotors[0] : First_2.Checked ? rotors[1] : First_3.Checked ? rotors[2] : rotors[3]); Rotor middle = new Rotor(Middle_1.Checked ? rotors[0] : Middle_2.Checked ? rotors[1] : Middle_3.Checked ? rotors[2] : rotors[3]); Rotor last = new Rotor(Last_1.Checked ? rotors[0] : Last_2.Checked ? rotors[1] : Last_3.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(first, int.Parse(Left_Position.Text), middle, int.Parse(Middle_Position.Text), last, int.Parse(Right_Position.Text), reflector); //output the answer string input = TextBox_Input.Text; string output = ""; foreach (char c in input) { output += machine.InputValue(int.Parse(c.ToString())); } TextBox_Output.Text = output; }
public Form1() { InitializeComponent(); //intialize routers and reflector 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 }); }
public Rotor(Rotor r) { for (int i = 0; i < r.offset.Count; i++) { offset.Add(r.offset[i]); } position = r.position; originalPosition = r.originalPosition; }