示例#1
0
        /// <summary>
        /// Copies the machine
        /// </summary>
        /// <returns>the copied machine</returns>
        public Machine DeepCopy()
        {
            Rotor[]   rotors    = new Rotor[this.Rotors.Length];
            Reflector reflector = this.Reflector.DeepCopy();
            Plugboard plugboard = this.Plugboard.DeepCopy();

            for (int i = 0; i < this.Rotors.Length; i++)
            {
                rotors[i] = this.Rotors[i].DeepCopy();
            }

            return(new Machine(rotors, reflector, plugboard));
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="rotors">the rotors of the machine</param>
        /// <param name="reflector">the reflectors of the machine</param>\
        /// <param name = "plugboard" > the plugboard of the machien</param>
        /// <param name="rotorMissingChars">the characters missing in the rotors and the index</param>
        /// <param name="reflectorMissingChars">the characters missing in the reflector</param>
        /// <param name="plugboardMissingChars">the characters missing in the plugboard</param>
        public RotorComparisionException(Rotor[] rotors, Reflector reflector, Plugboard plugboard,
                                         Dictionary <int, List <char> > rotorMissingChars, List <char> reflectorMissingChars,
                                         List <char> plugboardMissingChars)
        {
            this.rotors    = rotors;
            this.reflector = reflector;

            this.rotorMissingChars     = rotorMissingChars;
            this.reflectorMissingChars = reflectorMissingChars;

            this.plugboard             = plugboard;
            this.plugboardMissingChars = plugboardMissingChars;
        }
示例#3
0
        /// <summary>
        /// Checks the rotors and reflectors to ensure they share similar characters
        /// </summary>
        /// <param name="rotors">the rotor list</param>
        /// <param name="reflector">the reflector list</param>
        private void CheckMachineParameters(Rotor[] rotors, Reflector reflector, Plugboard plugboard)
        {
            // checks the rotors
            Dictionary <int, List <char> > rotorErrors = CompareRotors(rotors);
            // checks the reflectors
            List <char> reflectorError = CheckReflector(rotors[0], reflector);
            // checks the plugboard
            List <char> plugboardError = CheckPlugboard(rotors[0], plugboard);

            // if there are any errors, throw the exception
            if (reflectorError.Count > 0 || rotorErrors.Count > 0)
            {
                throw new RotorComparisionException(rotors, reflector, plugboard,
                                                    rotorErrors, reflectorError, plugboardError);
            }
        }
示例#4
0
        /// <summary>
        /// Constructor - Initializes a new machine
        /// </summary>
        /// <param name="rotors">the list of rotors that will be used</param>
        /// <param name="reflector">the reflector that will be used</param>
        /// <param name="plugboard">The plugboard that will be used</param>
        public Machine(Rotor[] rotors, Reflector reflector, Plugboard plugboard)
        {
            // attempts to set the rotors and reflectors
            try
            {
                CheckMachineParameters(rotors, reflector, plugboard);

                SetRotors(rotors);
                SetReflector(reflector);
                SetPlugboard(plugboard);
            }
            // catches any exceptions and rethrows it
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#5
0
 /// <summary>
 /// Sets the plugboard
 /// </summary>
 /// <param name="plugboard">the new plugboard</param>
 private void SetPlugboard(Plugboard plugboard)
 {
     machinePlugboard = plugboard.DeepCopy();
 }
示例#6
0
 /// <summary>
 /// Compares the plugboard to a rotor to ensure the characters match
 /// </summary>
 /// <param name="rotor">the rotor to check</param>
 /// <param name="plugboard">the plugboard to check</param>
 /// <returns>the list of invalid characters</returns>
 private List <char> CheckPlugboard(Rotor rotor, Plugboard plugboard)
 {
     return(BasicFunctions.CompareStringsCharacters(rotor.RotorString, plugboard.Combinations));
 }