private int rotorValue(Rotor r, int cPos, bool reverse) { int rPos = (int)r.ring - 65; int d; if (!reverse) { // Use this map when we're headed towards reflector. d = r.map[(26 + cPos + r.getOuterPosition() - rPos) % 26]; } else { //If we're returning from reflector use the other map. d = r.revMap[(26 + cPos + r.getOuterPosition() - rPos) % 26]; } return((cPos + d) % 26); }
//Constructor public EnigmaMachine(string fastR, string mediumR, string slowR, string refl, EnigmaSettings e) { string[] rotorsChoice = { slowR, mediumR, fastR, refl }; rotors = new Rotor[3]; //Initialize the plugboard. plugBoard = new Dictionary <char, char>(); // The notch, as well as alphabet is fixed. // We shall now create our rotors, to do so, requires we know the // Rotors which have been chosen. e.order = ""; for (int i = 0; i < 4; i++) { switch (rotorsChoice[i]) { case "I": rotors[i] = new Rotor(I, 'Q', "I"); e.order += (e.order.Equals(""))?"I":"-I"; break; case "II": rotors[i] = new Rotor(II, 'E', "II"); e.order += (e.order.Equals("")) ? "II" : "-II";; break; case "III": rotors[i] = new Rotor(III, 'V', "III"); e.order += (e.order.Equals("")) ? "III" : "-III";; break; case "IV": rotors[i] = new Rotor(IV, 'J', "IV"); e.order += (e.order.Equals("")) ? "IV" : "-IV";; break; case "V": rotors[i] = new Rotor(V, 'Z', "V"); e.order += (e.order.Equals("")) ? "V" : "-V";; break; case "VI": rotors[i] = new Naval_Rotor(VI, 'M', 'Z', "VI"); e.order += (e.order.Equals("")) ? "VI" : "-VI";; break; case "VII": rotors[i] = new Naval_Rotor(VII, 'M', 'Z', "VII"); e.order += (e.order.Equals("")) ? "VII" : "-VII";; break; case "VIII": rotors[i] = new Naval_Rotor(VIII, 'M', 'Z', "VIII"); e.order += (e.order.Equals("")) ? "VIII" : "-VIII";; break; case "A": reflector = new Rotor(A, ' ', ""); e.reflector = 'A'; break; case "B": reflector = new Rotor(B, ' ', ""); e.reflector = 'B'; break; case "C": reflector = new Rotor(C, ' ', ""); e.reflector = 'C'; break; } } }