Пример #1
0
        /// <summary>
        /// Compares 2 rotors
        /// </summary>
        /// <param name="rotor1"></param>
        /// <param name="rotor2"></param>
        /// <returns></returns>
        private List <char> CheckRotor(Rotor rotor1, Rotor rotor2)
        {
            List <char> errors =
                BasicFunctions.CompareStringsCharacters(rotor1.RotorString, rotor2.RotorString);

            return(errors);
        }
Пример #2
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));
        }
Пример #3
0
        /// <summary>
        /// Sets the rotor at the given index
        /// </summary>
        /// <param name="index">the index to change</param>
        /// <param name="newRotor">the settings of the new rotor</param>
        public void SetRotorAt(int index, Rotor newRotor)
        {
            List <char> errorCheck = CheckRotor(machineRotors[0], newRotor);

            if (errorCheck.Count > 0)
            {
                // creates a temporary array used for the exception
                Rotor[] temp = new Rotor[] { machineRotors[0], newRotor };
                // creates a dictionary to store the information
                Dictionary <int, List <char> > errors = new Dictionary <int, List <char> >();
                errors.Add(1, errorCheck);

                // throws the exception
                throw new RotorComparisionException(machineRotors, machineReflector, machinePlugboard,
                                                    errors, new List <char>(), new List <char>());
            }

            // save the rotor if no errors
            machineRotors[index] = newRotor.DeepCopy();
        }
Пример #4
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));
 }
Пример #5
0
 /// <summary>
 /// Checks the reflecor to ensure the characters match the rotor
 /// </summary>
 /// <param name="rotor">the rotor to check</param>
 /// <param name="reflector">the reflecor to check</param>
 /// <returns></returns>
 private List <char> CheckReflector(Rotor rotor, Reflector reflector)
 {
     return(BasicFunctions.CompareStringsCharacters(rotor.RotorString, reflector.ReflectorReflection));
 }