Пример #1
0
        /// <summary>
        /// Initialize a Enigma machine.
        /// </summary>
        public Enigma(Reflector reflector, PlugBoard plugBoard, params RotorEnigma[] rotors) : base(reflector.OperatingAlphabet)
        {
            if (reflector == null)
            {
                throw new ArgumentNullException(nameof(reflector));
            }
            Reflector = reflector;

            if (rotors == null)
            {
                rotors = new RotorEnigma[0];
            }
            Rotors = rotors;

            foreach (RotorEnigma rotor in rotors)
            {
                if (!Reflector.Equals(rotor))
                {
                    throw new ArgumentNullException("A rotor does not use the same Alphabet that the others.");
                }
            }

            Reset();

            if (plugBoard == null)
            {
                PlugBoard = new PlugBoard();
            }
            else
            {
                PlugBoard = plugBoard;
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a duplicate of this rotor and reset then.
        /// </summary>
        /// <returns></returns>
        new public RotorEnigma CloneRotor(bool andReset)
        {
            RotorEnigma rslt = new RotorEnigma(Id, source_alphabet, InitialPosition, RotateAt, RotateAtSecondary);

            if (!andReset)
            {
                rslt.RotateToPosition(OffsetPosition);
            }
            return(rslt);
        }