Esempio n. 1
0
        public void SetEncryptionKeyReturnsCorrectTextForOneRotor()
        {
            const string plaintext = "HELLO";

            Rotor[] rotors = new Rotor[1];

            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("A");
            Assert.AreEqual(AlphabetUtils.AlphabetString, enigma.SubmitString(AlphabetUtils.AlphabetString));
            Assert.AreEqual(AlphabetUtils.ReverseAlphabetString, enigma.SubmitString(AlphabetUtils.ReverseAlphabetString));
            Assert.AreEqual(plaintext, enigma.SubmitString(plaintext));
        }
Esempio n. 2
0
        public void SetEncryptionKeyReturnsCorrectTextForOneRotorAndOneDeflectorAndOneLetterInput()
        {
            const string plaintext = "A";

            Rotor[] rotors = new Rotor[2];

            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[1] = new Rotor(AlphabetUtils.ReverseAlphabetString, "reflector");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("BB");

            string ciphertext = enigma.SubmitString(plaintext);

            Assert.AreEqual(plaintext, enigma.SubmitString(ciphertext), "Encryption symmetry is not ensured.");
        }
Esempio n. 3
0
        public void SymmetryIsEnsuredWithOneFixedRotorAndReflector()
        {
            const string plaintext = "HELLO";

            Rotor[] rotors = new Rotor[2];
            rotors[0] = new Rotor(AlphabetUtils.AlphabetString, "rotor");
            rotors[1] = new Rotor(AlphabetUtils.ReverseAlphabetString, "reflector");

            Enigma enigma = new Enigma(rotors);

            enigma.SetEncryptionKey("BB");

            string ciphertext = enigma.SubmitString(plaintext);

            Assert.AreEqual(plaintext, enigma.SubmitString(ciphertext), "Encryption symmetry is not ensured.");
        }