Example #1
0
        /// <summary>
        /// Initialize a MarkMark machine.
        /// </summary>
        public MarkMark(Reflector reflector, PlugBoard frontPlugBoard, params Module[] modules) : base(reflector.OperatingAlphabet)
        {
            if (reflector == null)
            {
                throw new ArgumentNullException(nameof(reflector));
            }
            Reflector = reflector;

            if (modules == null)
            {
                modules = new Module[0];
            }
            Modules = modules;

            foreach (Module module in modules)
            {
                if (module.Rotor != null && !Reflector.Equals(module.Rotor))
                {
                    throw new ArgumentNullException("A rotor does not use the same Alphabet that the others.");
                }
            }

            if (frontPlugBoard == null)
            {
                frontPlugBoard = new PlugBoard();
            }
            else
            {
                FrontPlugBoard = frontPlugBoard;
            }
        }
Example #2
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;
            }
        }
Example #3
0
        /// <summary>
        /// Create a module for a <see cref="Machine.Rotor"/> and a <see cref="Machine.PlugBoard"/>
        /// </summary>
        /// <param name="plugBoard"></param>
        /// <param name="rotor"></param>
        public Module(PlugBoard plugBoard, Rotor rotor)
        {
            if (plugBoard == null && rotor == null)
            {
                throw new ArgumentNullException(null, "The " + nameof(rotor) + " and the " + nameof(plugBoard) + " may not be null.");
            }

            PlugBoard = plugBoard;
            Rotor     = rotor;
        }
Example #4
0
 /// <summary>
 /// Process the input signal to left output signal (Rotor then Plugs).
 /// </summary>
 /// <param name="input"></param>
 /// <returns></returns>
 public char ProcessLeft(char input)
 {
     if (Rotor != null)
     {
         input = Rotor.ProcessLeft(input);
     }
     if (PlugBoard != null)
     {
         input = PlugBoard.Process(input);
     }
     return(input);
 }
Example #5
0
 /// <summary></summary>
 public override string ToString()
 {
     if (Rotor != null)
     {
         return(PlugBoard.ToString());
     }
     else if (PlugBoard != null)
     {
         return(Rotor.ToString());
     }
     else
     {
         return(Rotor.ToString() + " / " + PlugBoard.ToString());
     }
 }
Example #6
0
 /// <summary>
 /// Creates a duplicate of this Module and reset then.
 /// </summary>
 /// <returns></returns>
 public Module CloneModule(bool andReset)
 {
     return(new Module(PlugBoard.Clone(), Rotor.Clone(andReset)));
 }
Example #7
0
 /// <summary>
 /// Create a module for a <see cref="Machine.PlugBoard"/>
 /// </summary>
 /// <param name="plugBoard"></param>
 public Module(PlugBoard plugBoard) : this(plugBoard, null)
 {
 }