Ejemplo n.º 1
0
        public void TestRingstellung()
        {
            EnigmaSettings settings = new EnigmaSettings();

            settings.Rotors.Add(Constants.Rotors.I);
            settings.Rotors.Add(Constants.Rotors.II);
            settings.Rotors.Add(Constants.Rotors.III);

            settings.RotorPositions.Add(Constants.Alpha.G);
            settings.RotorPositions.Add(Constants.Alpha.A);
            settings.RotorPositions.Add(Constants.Alpha.A);

            settings.Rotors[0].Ringstellung = Constants.Alpha.S;
            settings.Rotors[1].Ringstellung = Constants.Alpha.B;
            settings.Rotors[2].Ringstellung = Constants.Alpha.C;

            settings.Reflector = Constants.Reflectors.B;

            IEnigmaMachine engimaMachine = new EnigmaMachineBase(settings);

            Assert.AreEqual <string>("Y", engimaMachine.EncryptDecrypt("A"));
            Assert.AreEqual <string>("F", engimaMachine.EncryptDecrypt("A"));
            Assert.AreEqual <string>("F", engimaMachine.EncryptDecrypt("A"));
            Assert.AreEqual <string>("X", engimaMachine.EncryptDecrypt("A"));
            Assert.AreEqual <string>("D", engimaMachine.EncryptDecrypt("A"));
        }
Ejemplo n.º 2
0
        public void TestEnigmaMachineThrowIllegalCharacterExceptionOnInvalidCharacter()
        {
            IScramblerUnit scrambler = new Enigma.Fakes.StubIScramblerUnit()
            {
                ScrambleString = (S) => { return("A"); }
            };

            IPlugboard plugboard = new Enigma.Fakes.StubIPlugboard()
            {
                MapCharacterString = (S) => { return("A"); }
            };

            IEnigmaMachine machine = new EnigmaMachineBase(plugboard, scrambler);

            Assert.AreEqual <string>("A", machine.EncryptDecrypt("!@#$%^&*()"));
        }
Ejemplo n.º 3
0
        public void TestEnigmaMachineIgnoreDash()
        {
            IScramblerUnit scrambler = new Enigma.Fakes.StubIScramblerUnit()
            {
                ScrambleString = (S) => { return("A"); }
            };

            IPlugboard plugboard = new Enigma.Fakes.StubIPlugboard()
            {
                MapCharacterString = (S) => { return("A"); }
            };

            IEnigmaMachine machine = new EnigmaMachineBase(plugboard, scrambler);

            Assert.AreEqual <string>("-", machine.EncryptDecrypt("-"));
        }