public void CheckOperationBarbarosaMessage() { string expectedPlainText = "AUFKLXABTEILUNGXVONXKURTINOWAXKURTINOWAXNORDWESTLXSEBEZXSEBEZXUAFFLIEGERSTRASZERIQTUNGXDUBROWKIXDUBROWKIXOPOTSCHKAXOPOTSCHKAXUMXEINSAQTDREINULLXUHRANGETRETENXANGRIFFXINFXRGTX"; // Message Key: BLA // Reflector: B // Wheel order: II IV V // Ring positions: 02 21 12 // Plug Pairs: AV BS CG DL FU HZ IN KM OW RX Scrambler3 s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorII((Letters)1, Letters.B), Rotor.RotorIV((Letters)20, Letters.L), Rotor.RotorV((Letters)11, Letters.A)); Plugboard p = new Plugboard(new Dictionary <Letters, Letters> { { Letters.A, Letters.V }, { Letters.B, Letters.S }, { Letters.C, Letters.G }, { Letters.D, Letters.L }, { Letters.F, Letters.U }, { Letters.H, Letters.Z }, { Letters.I, Letters.N }, { Letters.K, Letters.M }, { Letters.O, Letters.W }, { Letters.R, Letters.X }, }); EnigmaM3 e = new EnigmaM3(s, p); string cypherText = "EDPUDNRGYSZRCXNUYTPOMRMBOFKTBZREZKMLXLVEFGUEYSIOZVEQMIKUBPMMYLKLTTDEISMDICAGYKUACTCDOMOHWXMUUIAUBSTSLRNBZSZWNRFXWFYSSXJZVIJHIDISHPRKLKAYUPADTXQSPINQMATLPIFSVKDASCTACDPBOPVHJK"; string plainText = e.GetOutput(cypherText); Assert.That(plainText, Is.EqualTo(expectedPlainText)); }
public void CheckInstructionManualMessage() { string expectedPlainText = "FEINDLIQEINFANTERIEKOLONNEBEOBAQTETXANFANGSUEDAUSGANGBAERWALDEXENDEDREIKMOSTWAERTSNEUSTADT"; // Message Key: ABL // Reflector: A // Wheel order: II I III // Ring positions: 24 13 22 // Plug Pairs: AM FI NV PS TU WZ Scrambler3 s = new Scrambler3(Reflector.ReflectorA(), Rotor.RotorII((Letters)23, Letters.A), Rotor.RotorI((Letters)12, Letters.B), Rotor.RotorIII((Letters)21, Letters.L)); Plugboard p = new Plugboard(new Dictionary <Letters, Letters> { { Letters.A, Letters.M }, { Letters.F, Letters.I }, { Letters.N, Letters.V }, { Letters.P, Letters.S }, { Letters.T, Letters.U }, { Letters.W, Letters.Z }, }); EnigmaM3 e = new EnigmaM3(s, p); string cypherText = "GCDSEAHUGWTQGRKVLFGXUCALXVYMIGMMNMFDXTGNVHVRMMEVOUYFZSLRHDRRXFJWCFHUHMUNZEFRDISIKBGPMYVXUZ"; string plainText = e.GetOutput(cypherText); Assert.That(plainText, Is.EqualTo(expectedPlainText)); }
public void CheckGandPReverseWithSameStartingConfiguration() { Scrambler s; Letters l; s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.A, Letters.Z)); l = s.GetOutput(Letters.G); Assert.That(l, Is.EqualTo(Letters.P)); s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.A, Letters.Z)); l = s.GetOutput(Letters.P); Assert.That(l, Is.EqualTo(Letters.G)); }
public void CheckEncypheredMessageDecyphers() { Scrambler s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.A, Letters.A)); Letters[] expectedPlaintext = LetterMapper.CreateLettersArray("THISISMYTESTMESSAGE"); Letters[] cyphertext = LetterMapper.CreateLettersArray("OPGNDXOEHCJEXBEDDUO"); Letters[] plaintext = new Letters[cyphertext.Length]; for (int i = 0; i < cyphertext.Length; i++) { plaintext[i] = s.GetOutput(cyphertext[i]); } Assert.That(plaintext, Is.EqualTo(expectedPlaintext)); }
public void CheckEncypheredMessageDecyphersWithRolloverAndRingF() { Scrambler s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.F, Letters.A)); Letters[] expectedPlaintext = LetterMapper.CreateLettersArray("THISMESSAGEWILLCAUSEROLLOVER"); Letters[] cyphertext = LetterMapper.CreateLettersArray("UFVWRFXPGFNQBAPWSVNSFXOGCPPK"); Letters[] plaintext = new Letters[cyphertext.Length]; for (int i = 0; i < cyphertext.Length; i++) { plaintext[i] = s.GetOutput(cyphertext[i]); } Assert.That(plaintext, Is.EqualTo(expectedPlaintext)); }
public void CheckEncypheredMessageDecyphersWithMoreRollover() { Scrambler s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.A, Letters.A)); Letters[] expectedPlaintext = LetterMapper.CreateLettersArray("BAUSSRLQONWLBSZPPAORUKKJPRUYZNOLRKKHFMLJRAVSPOJVTPGHRBLEPRVPZMZYNTBWBISKQUBDWIENKKPHHDZIXBUSROMKSBITTAKICWDIFWPINAMXTHWOOQWZWCEIPGKDRMIGIVRSLCEQGHGKXLCXARNZXWGJSICHWOVIUGPLUVNYYQLOONRJJRQNPSIHYMQXXMUOEEKQPVUFLCPUFFJLFWIDHTVBHFHLCJMKWYZWPJHCOBHYXJEOKOSHCMABEVUNHEFYBMFPQPHVQPLFSYFNESRLWBOIBUEMZHLAZFRJEYGVTSCZTKRTRVOLZEFNZPCYDPCNIYQEEJBNWWXSXSRIYAIVFOUVMBOGQZVWMPYVOAUBIOZWFZVVLGKMCOZMWCSCOXWNJRPPVVUUPRURVIWXIATKFHUTXJSNMHCQLKGTTKAFBTORKWHTUCMTXQJFKORXORVINKXGUNCALBJQHQQEWFCQQMBJYWFAWVSZSMFLHUBZEQYEGPBAXMNYVKJBXRMTLBVZTHPQBRPPSFMQRDLJLVUYUHQRYTEUURQSOGYUAEIJQMXSXFJFTLSOPYJLULMGJGXYBPVJHZAGFIBEPUKKEJMVQMGQMKFMZKXGRKGTSYAZLPUDRRWSOHWC"); Letters[] cyphertext = LetterMapper.CreateLettersArray("ADFNBTUOMHCRANIBRLEVTHRCQJCBVYGUEOMGUKCDTSUQJCUUOFNEKPBXHMQJKEUIXENMCLAHIWCCTJMSETLDMZWJWIYCCNWUHHHFNBWMBITTGETBVFAFRWUTYMQUPZHHRRHYWEJTBAMKJLILXFAZKDHVLDCXMUXDIQKUAXMUXRFYRDWKFFFHFAAQBKLTJNLBRQYUMXDAQZUDTGWGRGITLHPXPDMVOMDWOVBMKRGTRXUKNEDMNILPHYGNJJVOPXZRPRWAQSXERTQVXFPXVVZNTVXAYKLMVUEYZGQOLQSBEVYLRFOQSDUUMLPKAXLWRNBCMCNEFQMERXFIDSNGLBAMVBYOFVUOGNTOLSFKCROCEGOELRWSZTHDNHHISITKKDDUVEKLLDEGCPHWERBOLVTPQQVFBHDDYDSFDYKQLQTCJBUQYGVHVMSOOEDCEUBBPFQPGNIMTTZNSNDTFPMCODOLRZKXHBNTDTQYDNVZZBATJVLQVSVBGVEDBRWQAQUUPTTDPSGZJUWXVOUHNWQMQXHZABKGNUVPELJHVGORJXDYDFINOOYQAFKYORUPEBKNSCOARUUTSAGLWGILXMEPXDYJMSHXQOQRNAQYVJTETTZZPTQUEXYREZOXJTFCJNPK"); Letters[] plaintext = new Letters[cyphertext.Length]; for (int i = 0; i < cyphertext.Length; i++) { plaintext[i] = s.GetOutput(cyphertext[i]); } Assert.That(plaintext, Is.EqualTo(expectedPlaintext)); }
public void CheckEncypheredMessageDecyphersWithRollover() { Scrambler s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.A), Rotor.RotorII(Letters.A, Letters.A), Rotor.RotorIII(Letters.A, Letters.A)); Letters[] expectedPlaintext = LetterMapper.CreateLettersArray("THISISALONGMESSAGETOTESTROLLOVERINTHEROTORS"); Letters[] cyphertext = LetterMapper.CreateLettersArray("OPGNDXCGMHUNLNECJZGJUPLWOVMOJFUJWQXGSUDEJVY"); Letters[] plaintext = new Letters[cyphertext.Length]; for (int i = 0; i < cyphertext.Length; i++) { plaintext[i] = s.GetOutput(cyphertext[i]); } Assert.That(plaintext, Is.EqualTo(expectedPlaintext)); }
public void CheckFiveAWithRingBGivesCorrectOutput() { //With the rotors I, II, III (from left to right), wide B-reflector, all ring settings in B-position, and start position AAA, typing AAAAA will produce the encoded sequence EWTYX. Scrambler3 s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.B, Letters.A), Rotor.RotorII(Letters.B, Letters.A), Rotor.RotorIII(Letters.B, Letters.A)); Letters l; l = s.GetOutput(Letters.A); Assert.That(l, Is.EqualTo(Letters.E)); l = s.GetOutput(Letters.A); Assert.That(l, Is.EqualTo(Letters.W)); l = s.GetOutput(Letters.A); Assert.That(l, Is.EqualTo(Letters.T)); l = s.GetOutput(Letters.A); Assert.That(l, Is.EqualTo(Letters.Y)); l = s.GetOutput(Letters.A); Assert.That(l, Is.EqualTo(Letters.X)); }
public void LetchworthEnigmaTestsB() { // | | | | // Plaintext "crib" A T T A C K A T D A W N A T T A C K A T D A W N // Ciphertext W I F K B G Z L H N I M K Q R M B V B Z S R E E // Message position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 // Upper drum setting Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z // Middle drum setting Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z // Lower drum setting A B C D E F G H I J K L M N O P Q R S T U V W X // Menu A->Z Z->T T->R R->A // 7 // a - z // 22 | | 20 // R - T // 15 // validate input produces output EnigmaM3 e = new EnigmaM3(new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.J), Rotor.RotorII(Letters.A, Letters.K), Rotor.RotorIII(Letters.A, Letters.L)), new Plugboard(new Dictionary <Letters, Letters>())); string plainText = "ATTACKATDAWNATTACKATDAWN"; string cypherText = e.GetOutput(plainText); Assert.That(cypherText, Is.EqualTo("WIFKBGZLHNIMKQRMBVBZSREE")); // set up l1 at offset 7/G Scrambler3 s1 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.G)); LetchworthEnigma l1 = new LetchworthEnigma(s1); // set up l2 at offset 20/T Scrambler3 s2 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.T)); LetchworthEnigma l2 = new LetchworthEnigma(s2); // set up l3 at offset 15/O Scrambler3 s3 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.O)); LetchworthEnigma l3 = new LetchworthEnigma(s3); // set up l4 at offset 22/V Scrambler3 s4 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.V)); LetchworthEnigma l4 = new LetchworthEnigma(s4); Scrambler3 s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.Z)); LetchworthEnigma l = new LetchworthEnigma(s); bool found = false; // check all combinations with relative offsets for (int i = 0; i < (26 * 25 * 26); i++) { Letters o1 = l1.GetOutput(Letters.A); Letters o2 = l2.GetOutput(Letters.Z); Letters o3 = l3.GetOutput(Letters.T); Letters o4 = l4.GetOutput(Letters.R); l.GetOutput(Letters.A); // input/output doesn't matter if (o1 == Letters.Z && o2 == Letters.T && o3 == Letters.R && o4 == Letters.A) { found = true; } } ; // TODO: get initial settings from startup settings // run another letchworthEnigma starting at initial settings? tick it over at same rate Assert.That(found, Is.True); }
public void LetchworthEnigmaTests() { // | | | // Plaintext "crib" A T T A C K A T D A W N // Ciphertext W A Z X L E C C X B U P // Message position 1 2 3 4 5 6 7 8 9 10 11 12 // Upper drum setting Z Z Z Z Z Z Z Z Z Z Z Z // Middle drum setting Z Z Z Z Z Z Z Z Z Z Z Z // Lower drum setting A B C D E F G H I J K L // Menu ATC // 2 // A - T // 7 \ / 8 // C // validate input produces output EnigmaM3 e = new EnigmaM3(new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.A)), new Plugboard(new Dictionary <Letters, Letters>())); string plainText = "ATTACKATDAWN"; string cypherText = e.GetOutput(plainText); Assert.That(cypherText, Is.EqualTo("WAZXLECCXBUP")); // set up l1 at offset A/1 (B/2) Scrambler3 s1 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.B)); LetchworthEnigma l1 = new LetchworthEnigma(s1); // set up l2 at offset F/6 (G/7) Scrambler3 s2 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.G)); LetchworthEnigma l2 = new LetchworthEnigma(s2); // set up l3 at offset G/7 (H/8) Scrambler3 s3 = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.H)); LetchworthEnigma l3 = new LetchworthEnigma(s3); Scrambler3 s = new Scrambler3(Reflector.ReflectorB(), Rotor.RotorI(Letters.A, Letters.Z), Rotor.RotorII(Letters.A, Letters.Z), Rotor.RotorIII(Letters.A, Letters.Z)); LetchworthEnigma l = new LetchworthEnigma(s); bool found = false; // check all combinations with relative offsets for (int i = 0; i < (26 * 25 * 26); i++) { Letters o1 = l1.GetOutput(Letters.T); Letters o2 = l2.GetOutput(Letters.A); Letters o3 = l3.GetOutput(Letters.T); l.GetOutput(Letters.A); // input/output doesn't matter if (o1 == Letters.A && o2 == Letters.C && o3 == Letters.C) { found = true; } } ; // TODO: get initial settings from startup settings // run another letchworthEnigma starting at initial settings? tick it over at same rate Assert.That(found, Is.True); }
public EnigmaM3(Scrambler3 scrambler, Plugboard plugboard) : base(scrambler, plugboard) { }
public LetchworthEnigma(Scrambler3 scrambler) { m_scrambler = scrambler; }