public void TestRotorGroupEnigmaTest2() { List <int> fop1 = new List <int> { 17, }; List <int> fop2 = new List <int> { 5, }; List <int> fop3 = new List <int> { 22, }; Rotor rotorOne = new Rotor("Rotor III", 1, fop1); Rotor rotorTwo = new Rotor("Rotor II", 1, fop2); Rotor rotorThree = new Rotor("Rotor I", 1, fop3); Reflector reflector = new Reflector("B"); RotorGroup rg = new RotorGroup(rotorOne, rotorTwo, rotorThree, reflector); string expectedOut = "pgqpwitkgv"; string enigmaOut = ""; foreach (char c in "aaaaaaaaaa") { enigmaOut += rg.RotorEncrypt(c); } Assert.AreEqual(enigmaOut, expectedOut); }
public void TestLargeEncoding1_30() { List <int> rotorOrder = new List <int>() { 1, 2, 3 }; List <int> rotorStartPos = new List <int>() { 0, 0, 0 }; RotorGroup rg = CreateTestRotorGroup.CreateTestRotor(rotorOrder, rotorStartPos); const string testInput = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; const string expectedOut = "bdzgowcxltksbtmcdlpbmuqofxyhcx"; string actualOut = ""; foreach (char c in testInput) { actualOut += rg.RotorEncrypt(c); } Assert.AreEqual(expectedOut, actualOut); }
public static RotorGroup CreateTestRotor(List <int> rotorOrder, List <int> rotorStartPos) { List <int> fop1 = new List <int> { 17, }; List <int> fop2 = new List <int> { 5, }; List <int> fop3 = new List <int> { 22, }; Rotor rotorOne = null; Rotor rotorTwo = null; Rotor rotorThree = null; int pos = 1; foreach (int rotor in rotorOrder) { string rotorName = ""; List <int> fopCur = null; switch (rotor) { case 1: rotorName = "Rotor I"; fopCur = fop1; break; case 2: rotorName = "Rotor II"; fopCur = fop2; break; case 3: fopCur = fop3; rotorName = "Rotor III"; break; } switch (pos) { case 1: rotorOne = new Rotor(rotorName, rotorStartPos[pos], fopCur); break; case 2: rotorTwo = new Rotor(rotorName, rotorStartPos[pos], fopCur); break; case 3: rotorThree = new Rotor(rotorName, rotorStartPos[pos], fopCur); break; } pos++; } Reflector reflector = new Reflector("B"); RotorGroup rg = new RotorGroup(rotorOne, rotorTwo, rotorThree, reflector); return(rg); }