private static char Method(char symbol, Rotor rotor, bool forward) { int wiringPosition = rotor.Position - rotor.Ringstellung; if (wiringPosition < 0) { wiringPosition = wiringPosition + 26; } int index = alphabet.IndexOf(symbol) + wiringPosition; if (index >= 26) { index = index - 26; } if (forward) { symbol = rotor.Wiring[index]; index = alphabet.IndexOf(symbol) - wiringPosition; } else { symbol = alphabet[index]; index = rotor.Wiring.IndexOf(symbol) - wiringPosition; } if (index < 0) { index = index + 26; } symbol = alphabet[index]; return(symbol); }
public RotorGroup(Rotor _rotor1, Rotor _rotor2, Rotor _rotor3, Reflector _reflector) { Rotor1 = _rotor1; Rotor2 = _rotor2; Rotor3 = _rotor3; Reflector = _reflector; }
private Reflector reflector; // define the reflector public Enigma(int Rotor1, int Rotor2, int Rotor3) { L = new Rotor(rotors[Rotor1 - 1], notches[Rotor1 - 1]); // define the 3 rotors the machine has and the reflector M = new Rotor(rotors[Rotor2 - 1], notches[Rotor2 - 1]); R = new Rotor(rotors[Rotor3 - 1], notches[Rotor3 - 1]); reflector = new Reflector(reflectorPerm); }
static void Main(string[] args) { Rotor RotorA = new Rotor(0, "DMTWSILRUYQNKFEJCAZBPGXOHV"); RotorA.Index = 15; Rotor RotorB = new Rotor(0, "HQZGPJTMOBLNCIFDYAWVEUSRKX"); RotorB.Index = 13; Rotor RotorC = new Rotor(0, "UQNTLSZFMREHDPXKIBVYGJCWOA"); RotorC.Index = 20; Switchboard SwitchboardA = new Switchboard("AJDKSIRUXBLHWTMCQGZNPYFVOE"); Reflector ReflectorA = new Reflector("YRUHQSLDPXNGOKMIEBFZCWVJAT"); EnigmaMachine Machine1 = new EnigmaMachine(SwitchboardA, new List <Rotor> { RotorA, RotorB, RotorC }, ReflectorA); ConsoleKeyInfo Key; do { Key = Console.ReadKey(true); if (Key.Key != ConsoleKey.Enter) { Console.Title = String.Format("Rotor Position {1},{2},{3} : Received {0}", char.ToUpper(Key.KeyChar), RotorA.Index, RotorB.Index, RotorC.Index); Console.Write((char)(Machine1.GetNextKey(char.ToUpper(Key.KeyChar) - 64) + 64)); } } while (Key.Key != ConsoleKey.Enter); }
static void TestRotors() { Rotor rotorIII = Rotor.III; Rotor rotorVI = Rotor.VI; Rotor rotorI = Rotor.I; for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorIII.In(ch); char och = rotorIII.Out(ech); Console.WriteLine("{0} => {1} => {2}", ch, ech, och); } Console.WriteLine("________________________________"); Console.ReadLine(); for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorVI.In(ch); char och = rotorVI.Out(ech); Console.WriteLine("{0} => {1} => {2}", ch, ech, och); } Console.WriteLine("________________________________"); Console.ReadLine(); for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorI.In(ch); char och = rotorI.Out(ech); Console.WriteLine("{0} => {1} => {2}", ch, ech, och); } Console.WriteLine("________________________________"); Console.ReadLine(); Reflector reflector = Reflector.A; rotorIII.Increment(); for (char ch = 'A'; ch <= 'Z'; ch++) { char c1 = rotorIII.In(ch); char c2 = rotorVI.In(c1); char c3 = rotorI.In(c2); char r = reflector.Reflect(c3); char c4 = rotorI.Out(r); char c5 = rotorVI.Out(c4); char c6 = rotorIII.Out(c5); Console.WriteLine("{0} => {1} => {2} => {3} => {4} => {5} => {6} => {7}", ch, c1, c2, c3, r, c4, c5, c6); char dc1 = rotorIII.In(c6); char dc2 = rotorVI.In(dc1); char dc3 = rotorI.In(dc2); char dr = reflector.Reflect(dc3); char dc4 = rotorI.Out(dr); char dc5 = rotorVI.Out(dc4); char dc6 = rotorIII.Out(dc5); Console.WriteLine("{7} <= {6} <= {5} <= {4} <= {3} <= {2} <= {1} <= {0}", c6, dc1, dc2, dc3, dr, dc4, dc5, dc6); Console.WriteLine("______________________________________________________________________________________"); Console.ReadLine(); } }
static void TestRotors() { Rotor rotorIII = Rotor.III; Rotor rotorVI = Rotor.VI; Rotor rotorI = Rotor.I; for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorIII.In(ch); char och = rotorIII.Out(ech); Console.WriteLine("{0} => {1} => {2}", ch, ech, och); } Console.WriteLine("________________________________"); Console.ReadLine(); for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorVI.In(ch); char och = rotorVI.Out(ech); Console.WriteLine($"{ch} => {ech} => {och}"); } Console.WriteLine("________________________________"); Console.ReadLine(); for (char ch = 'A'; ch <= 'Z'; ch++) { char ech = rotorI.In(ch); char och = rotorI.Out(ech); Console.WriteLine($"{ch} => {ech} => {och}"); } Console.WriteLine("________________________________"); Console.ReadLine(); Reflector reflector = Reflector.A; rotorIII.Increment(); for (char ch = 'A'; ch <= 'Z'; ch++) { char c1 = rotorIII.In(ch); char c2 = rotorVI.In(c1); char c3 = rotorI.In(c2); char r = reflector.Reflect(c3); char c4 = rotorI.Out(r); char c5 = rotorVI.Out(c4); char c6 = rotorIII.Out(c5); Console.WriteLine($"{ch} => {c1} => {c2} => {c3} => {r} => {c4} => {c5} => {c6}"); char dc1 = rotorIII.In(c6); char dc2 = rotorVI.In(dc1); char dc3 = rotorI.In(dc2); char dr = reflector.Reflect(dc3); char dc4 = rotorI.Out(dr); char dc5 = rotorVI.Out(dc4); char dc6 = rotorIII.Out(dc5); Console.WriteLine($"{dc6} <= {dc5} <= {dc4} <= {dr} <= {dc3} <= {dc2} <= {dc1} <= {c6}"); Console.WriteLine("______________________________________________________________________________________"); Console.ReadLine(); } }
public string EncryptMessage(string message) { string textToProcess = message.ToUpper(); string outputText = ""; foreach (char value in textToProcess) { if (value == ' ') { continue; } else { char character; char finalCharacter; if (_rotors[0].TurnRotor()) { int value1 = _rotors[0].GetOutput(); if (_rotors[1].TurnRotor()) { int value2 = _rotors[1].GetOutput(value1); if (_rotors[2].TurnRotor()) { int value3 = _rotors[2].GetOutput(value2); character = Rotor.ConvertIndexToCharacter(value3); finalCharacter = _plugboard.GetFinalCharacter(character); outputText += character; } else { character = Rotor.ConvertIndexToCharacter(value2); finalCharacter = _plugboard.GetFinalCharacter(character); outputText += character; } } else { character = Rotor.ConvertIndexToCharacter(value1); finalCharacter = _plugboard.GetFinalCharacter(character); outputText += character; } } else { character = Rotor.ConvertIndexToCharacter(_rotors[0].GetOutput()); finalCharacter = _plugboard.GetFinalCharacter(character); outputText += character; } } } return(outputText); }
public void Configurar_WithZ_ReturnsTrue() { string lResultado; string lResultadoEsperado = "ZABCDEFGHIJKLMNOPQRSTUVWXY"; Rotor lRotor = new Rotor(1); lRotor.Configurar('Z'); lResultado = lRotor.Anillo.ToString(); Assert.AreEqual(lResultadoEsperado, lResultado); }
static void Main(string[] args) { List <int> fop1 = new List <int> { 17, }; //rotor FoP are 0-25 (offset amounts) so If stepping from V-W it would normally be 22-23 but will be stepping 21-22 with 0 base List <int> fop2 = new List <int> { 5, }; List <int> fop3 = new List <int> { 22, }; Rotor rotor1 = new Rotor("Rotor III", 0, fop3); Rotor rotor2 = new Rotor("Rotor II", 0, fop2); Rotor rotor3 = new Rotor("Rotor I", 0, fop1); Reflector reflector = new Reflector("B"); RotorGroup rg = new RotorGroup(rotor1, rotor2, rotor3, reflector); int count = 0; int count2 = 0; foreach (char c in "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") { count2++; if (count == 5) { Console.WriteLine(); count = 0; } count++; Console.Write(rg.RotorEncrypt(c)); } Console.WriteLine(); count = 0; foreach (char c in "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa") { count2++; if (count == 5) { Console.WriteLine(); count = 0; } count++; if (count2 == 100) { Console.Write(""); } Console.Write(rg.RotorEncrypt(c)); } }
// Constructor public EnigmaMachine() { plugBoard = new Dictionary <char, char>(); // Notch and alphabet are fixed on the rotor // First argument is alphabet, second is the turnover notch Rotor rI = new Rotor(rotorIconf, 'Q', "I"); Rotor rII = new Rotor(rotorIIconf, 'E', "II"); Rotor rIII = new Rotor(rotorIIIconf, 'V', "III"); rotors = new Rotor[] { rI, rII, rIII }; // Default ordering of rotors reflector = new Rotor(reflectorAconf, ' ', ""); }
public EnigmaMachine() { AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(AssemblyResolver); InitializeComponent(); rotorsToolStripMenuItem_Click(null, null); panel6.BackColor = Color.FromArgb(7, 7, 7); left_Rotor = new Rotor("I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", 1, 17); mid_Rotor = new Rotor("II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", 1, 5); right_Rotor = new Rotor("III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", 1, 22); extra_Rotor = new Rotor("IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", 1, 10); reflector = new Reflector("B", "B", "YRUHQSLDPXNGOKMIEBFZCWVJAT"); DisplayPlugboard(); Display_Rotors(); }
private int rotorValue(Rotor r, int cPos, bool reverse) { int rPos = (int)r.ring - 65; int d; if (!reverse) { d = r.map[(26 + cPos + r.getOuterPosition() - rPos) % 26]; } else { d = r.revMap[(26 + cPos + r.getOuterPosition() - rPos) % 26]; } return((cPos + d) % 26); }
public void Cifrar_WithA_1Rotor_ReturnsTrue() { char lResultado; char lResultadoEsperado = 'P'; char lLetra = 'A'; char lConfInicial = 'A'; Rotor lRotor = new Rotor(1); lRotor.Configurar(lConfInicial); Rotores lRotores = new Rotores(); MethodInfo methodInfo = lRotores.GetType().GetMethod("AgregarRotor", BindingFlags.Instance | BindingFlags.NonPublic); methodInfo.Invoke(lRotores, new object[] { lRotor }); // lRotores.AgregarRotor(lRotor1); lResultado = lRotores.Cifrar(true, lLetra); Assert.AreEqual(lResultadoEsperado, lResultado); }
public void setSettings(char[] rings, char[] grund, string rotorOrder) { Rotor rI = null; Rotor rII = null; Rotor rIII = null; // Get the current ordering for (int i = 0; i < rotors.Length; i++) { if (rotors[i].name == "I") { rI = rotors[i]; } if (rotors[i].name == "II") { rII = rotors[i]; } if (rotors[i].name == "III") { rIII = rotors[i]; } } string[] order = rotorOrder.Split('-'); // Set the new ordering for (int i = 0; i < order.Length; i++) { if (order[i] == "I") { rotors[i] = rI; } if (order[i] == "II") { rotors[i] = rII; } if (order[i] == "III") { rotors[i] = rIII; } } setSettings(rings, grund); }
public void setSettings(char[] rings, char[] initialPos, List <string> rotorOrder) { if (rings.Length != 3 || initialPos.Length != 3 || rotorOrder.Count != 3) { throw new Exception("Array must consist of 3 items"); } selectedRotors.Clear(); foreach (string rotorName in rotorOrder) { Rotor rotor = rotors.Find(r => r.name == rotorName); selectedRotors.Add(rotor); } for (int i = 0; i < selectedRotors.Count; i++) { selectedRotors[i].ringSetting = Char.ToUpper(rings[i]); selectedRotors[i].setDisplayChar(Char.ToUpper(initialPos[i])); } }
public EnigmaMachine(Rotor rotor1, Rotor rotor2, Rotor rotor3, Rotor rotor4 = null, Rotor rotor5 = null, Reflector reflector = null) { EncodeSpacesAs = 'X'; Rotors = new List <Rotor>() { rotor1, rotor2, rotor3 }; if (rotor4 != null) { Rotors.Add(rotor4); if (rotor5 == null) { throw new EnigmaRulesException("Enigma Machines only had 3 or 5 rotors."); } Rotors.Add(rotor5); } PlugBoard = new PlugBoard(); Reflector = reflector == null ? Reflector.ETW : reflector; }
private void RotorsChange(Rotor R, string RotorNumber) { if (RotorNumber == "I") { R.Updatelayout("EKMFLGDQVZNTOWYHXUSPAIBRCJ"); R.UpdatenotchPosition('R'); } if (RotorNumber == "II") { R.Updatelayout("AJDKSIRUXBLHWTMCQGZNPYFVOE"); R.UpdatenotchPosition('F'); } if (RotorNumber == "III") { R.Updatelayout("BDFHJLCPRTXVZNYEIWGAKMUSQO"); R.UpdatenotchPosition('W'); } if (RotorNumber == "IV") { R.Updatelayout("ESOVPZJAYQUIRHXLNFTGKDCMWB"); R.UpdatenotchPosition('K'); } if (RotorNumber == "V") { R.Updatelayout("VZBRGITYUPSDNHLXAWMJQOFECK"); R.UpdatenotchPosition('A'); } }
private void reel_extra_label_Click(object sender, EventArgs e) { SetRotor setRotor = new SetRotor(extra_Rotor); var result = setRotor.ShowDialog(); if (result == DialogResult.OK) { extra_Rotor = setRotor.GetRotor; Display_Rotors(); } }
public SetRotor(Rotor rotor = null, bool extraRotor = false) { InitializeComponent(); if (extraRotor) { } if (rotor != null) { if (rotorI.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(0, true); checkedListBox.SetSelected(0, true); rotorI.Notch = rotor.Notch; rotorI.Ring_POS = rotor.Ring_POS; } if (rotorII.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(1, true); checkedListBox.SetSelected(1, true); rotorII.Notch = rotor.Notch; rotorII.Ring_POS = rotor.Ring_POS; } if (rotorIII.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(2, true); checkedListBox.SetSelected(2, true); rotorIII.Notch = rotor.Notch; rotorIII.Ring_POS = rotor.Ring_POS; } if (rotorIV.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(3, true); checkedListBox.SetSelected(3, true); rotorIV.Notch = rotor.Notch; rotorIV.Ring_POS = rotor.Ring_POS; } if (rotorV.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(4, true); checkedListBox.SetSelected(4, true); rotorV.Notch = rotor.Notch; rotorV.Ring_POS = rotor.Ring_POS; } if (rotorVI.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(5, true); checkedListBox.SetSelected(5, true); rotorVI.Notch = rotor.Notch; rotorVI.Ring_POS = rotor.Ring_POS; } if (rotorVII.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(6, true); checkedListBox.SetSelected(6, true); rotorVII.Notch = rotor.Notch; rotorVII.Ring_POS = rotor.Ring_POS; } if (rotorVIII.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(7, true); checkedListBox.SetSelected(7, true); rotorVIII.Notch = rotor.Notch; rotorVIII.Ring_POS = rotor.Ring_POS; } if (rotorBeta.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(8, true); checkedListBox.SetSelected(8, true); rotorBeta.Notch = rotor.Notch; rotorBeta.Ring_POS = rotor.Ring_POS; } if (rotorGamma.Get_Rotor_ID == rotor.Get_Rotor_ID) { checkedListBox.SetItemChecked(9, true); checkedListBox.SetSelected(9, true); rotorGamma.Notch = rotor.Notch; rotorGamma.Ring_POS = rotor.Ring_POS; } SetParams(); } }
public EnigmaMachine(RotorName[] rotors, int[] startingPoints) { _rotors[0] = new Rotor(rotors[0], startingPoints[0]); _rotors[1] = new Rotor(rotors[1], startingPoints[1]); _rotors[2] = new Rotor(rotors[2], startingPoints[2]); }
private void button2_Click(object sender, EventArgs e) { rotorI = new Rotor("I", "EKMFLGDQVZNTOWYHXUSPAIBRCJ", 1, 17, 0); rotorII = new Rotor("II", "AJDKSIRUXBLHWTMCQGZNPYFVOE", 1, 5, 1); rotorIII = new Rotor("III", "BDFHJLCPRTXVZNYEIWGAKMUSQO", 1, 22, 2); rotorIV = new Rotor("IV", "ESOVPZJAYQUIRHXLNFTGKDCMWB", 1, 10, 3); rotorV = new Rotor("V", "VZBRGITYUPSDNHLXAWMJQOFECK", 1, 26, 4); rotorVI = new Rotor("VI", "VZBRGITYUPSDNHLXAWMJQOFECK", 1, 26, 5, true); rotorVII = new Rotor("VII", "VZBRGITYUPSDNHLXAWMJQOFECK", 1, 26, 6, true); rotorVIII = new Rotor("VIII", "VZBRGITYUPSDNHLXAWMJQOFECK", 1, 26, 7, true); rotorBeta = new Rotor("β", "LEYJVCNIXWPBQMDRTAKZGFUHOS", 1, 26, 8); rotorGamma = new Rotor("γ", "FSOKANUERHMBTIYCWLQPZXVGJD", 1, 26, 9); SetParams(); }
/// <summary> /// Agrega un rotor /// </summary> /// <param name="pRotor">Rotor a agregar</param> private void AgregarRotor(Rotor pRotor) { ListaRotores.Add(pRotor); }
/// <summary> /// Inicializa los rotores segun el vector /// </summary> /// <param name="pRotores">Vector que contiene los numeros de rotor a utilizar</param> public void Inicializar(int[] pRotores) { EliminarRotores(); for (int i = 1; i <= pRotores.Length; i++) { Rotor lRotor = new Rotor(i); AgregarRotor(lRotor); } }
private void loadConfigToolStripMenuItem_Click(object sender, EventArgs e) { try { string config = null; OpenFileDialog openfile = new OpenFileDialog(); openfile.Filter = "Enigma Config|*.enigma"; if (openfile.ShowDialog() == DialogResult.OK) using (StreamReader sr = new StreamReader(openfile.FileName)) config = sr.ReadToEnd(); string[] data = config.Split('|'); if (data.Length == 19) { string t = data[0]; SetRotor setRotor = new SetRotor(); right_Rotor = setRotor.GetBasicRotorById(data[0]); right_Rotor.Ring_POS = Convert.ToInt32(data[1]); right_Rotor.Notch = Convert.ToInt32(data[2]); mid_Rotor = setRotor.GetBasicRotorById(data[3]); mid_Rotor.Ring_POS = Convert.ToInt32(data[4]); mid_Rotor.Notch = Convert.ToInt32(data[5]); left_Rotor = setRotor.GetBasicRotorById(data[6]); left_Rotor.Ring_POS = Convert.ToInt32(data[7]); left_Rotor.Notch = Convert.ToInt32(data[8]); extra_Rotor = setRotor.GetBasicRotorById(data[9]); extra_Rotor.Ring_POS = Convert.ToInt32(data[10]); extra_Rotor.Notch = Convert.ToInt32(data[11]); extraRotor.Enabled = Convert.ToBoolean(data[12]); extraRotor.Visible = Convert.ToBoolean(data[12]); SetReflector setReflector = new SetReflector(); reflector = setReflector.GetReflectorById(data[13]); plugboard.Plug_Out = data[14]; extra_Rotor.Rotor_POS = Convert.ToInt32(data[15]); left_Rotor.Rotor_POS = Convert.ToInt32(data[16]); mid_Rotor.Rotor_POS = Convert.ToInt32(data[17]); right_Rotor.Rotor_POS = Convert.ToInt32(data[18]); setRotor.Dispose(); setReflector.Dispose(); if (extraRotor.Enabled) rotorsToolStripMenuItem1_Click(null, null); else rotorsToolStripMenuItem_Click(null, null); DisplayPlugboard(); Display_Rotors(); ViewSettings("Enigma Settings That Were Loaded"); } } catch { MessageBox.Show("There was a problem loading config data.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { char[] defaultIndex = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ' }; char[] rotor1Array = { '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', ' ' }; char[] rotor2Array = { '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[] rotor3Array = { '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', ' ' }; char[] reflectorArray = { 'E', 'J', 'M', 'Z', 'A', 'L', 'Y', 'X', 'V', 'B', 'W', 'F', 'C', 'R', 'Q', 'U', 'O', 'N', 'T', 'S', 'P', 'I', 'K', 'H', 'G', 'D', ' ' }; Rotor rotor1 = new Rotor(rotor1Array); Rotor rotor2 = new Rotor(rotor2Array); Rotor rotor3 = new Rotor(rotor3Array); Rotor[] mainRotorArray = { rotor1, rotor2, rotor3 }; //Console.WriteLine("Rotors Created"); Rotor reflector = new Rotor(reflectorArray); //Console.WriteLine("Reflector Created"); //rotor1.displayRotor(); //rotor2.displayRotor(); //rotor3.displayRotor(); //reflector.displayRotor(); setInitialRotorPositions(mainRotorArray); //Console.WriteLine("Rotators Set to Initial Position"); //rotor1.displayRotor(); //rotor2.displayRotor(); //rotor3.displayRotor(); //reflector.displayRotor(); Console.Write("Enter String: "); String message = Console.ReadLine(); message = message.ToUpperInvariant(); System.Text.StringBuilder output = new System.Text.StringBuilder(); //char[] messageChars = message.ToCharArray(); int i = 0, j = 0; foreach (char c in message) { char character = c; //Console.WriteLine(character); character = rotor1.getCharAtPos(Array.IndexOf(defaultIndex, character)); // Return character from rotor1 at same index of chatacter in defaultArray character = rotor2.getCharAtPos(Array.IndexOf(defaultIndex, character)); // Return character from rotor2 at same index of character in defaultArray character = rotor3.getCharAtPos(Array.IndexOf(defaultIndex, character)); // Return character from rotor3 at same index of character in defaultArray character = reflector.getCharAtPos(Array.IndexOf(defaultIndex, character)); // Return character from reflector at same index of character in defaultArray character = defaultIndex[Array.IndexOf(rotor3.getRotorArray(), character)]; // Return character from defaultArray at same index of character in rotor3 character = defaultIndex[Array.IndexOf(rotor2.getRotorArray(), character)]; // Return character from defaultArray at same index of character in rotor2 character = defaultIndex[Array.IndexOf(rotor1.getRotorArray(), character)]; // Return character from defaultArray at same index of character in rotor1 output.Append(character); i++; //Rotate Rotors rotor1.rotateRotor(); // Rotor 1 rotates every turn if (i == 27) { i = 0; rotor2.rotateRotor(); j++; } if (j == 27) { j = 0; rotor3.rotateRotor(); } } Console.WriteLine("\"{0}\"", output); }