Example #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);
        }
Example #2
0
        /// <summary>
        /// Checks to make sure the strings are the same
        /// </summary>
        /// <param name="str">the string used to cross the rotor</param>
        /// <param name="cypher">the cypher used in the rotor</param>
        private void CheckStrings(string str, string cypher)
        {
            // stores any errors that may occur
            Dictionary <POTENTIAL_ERRORS, List <char> > errors
                = new Dictionary <POTENTIAL_ERRORS, List <char> >();

            // a list that stores the information that is checked
            List <char> currentCheck = new List <char>();

            // check for dublicates in str
            currentCheck = BasicFunctions.DuplicatedCharacters(str);

            if (currentCheck.Count > 0) // if there are dublicates in the string
            {
                errors.Add(POTENTIAL_ERRORS.Dublicates_FromString, currentCheck);
            }

            // check for dublicates in cypher
            currentCheck = BasicFunctions.DuplicatedCharacters(cypher);

            if (currentCheck.Count > 0) // if there are duplicates in the cypher
            {
                errors.Add(POTENTIAL_ERRORS.Dublicates_FromCypher, currentCheck);
            }

            // look for missing letters
            currentCheck = BasicFunctions.CompareStringsCharacters(cypher, str);
            if (currentCheck.Count > 0) // if there are letters missing in the string
            {
                errors.Add(POTENTIAL_ERRORS.Missing_FromString, currentCheck);
            }

            currentCheck = BasicFunctions.CompareStringsCharacters(str, cypher);
            if (currentCheck.Count > 0) // if there are letters missing in the cypher
            {
                errors.Add(POTENTIAL_ERRORS.Missing_FromCypher, currentCheck);
            }


            // if everything is valid
            if (errors.Count == 0)
            {
                rotorString = str;
                rotorCypher = cypher;
            }
            else
            {
                // throw exception
                throw new InvalidRotorSettingsException(errors, str, cypher, DisplayRotationLetters());
            }
        }
Example #3
0
        /// <summary>
        /// Checks the rotors to ensure they have the same values
        /// </summary>
        /// <param name="rotors">the rotors</param>
        /// <returns>the dictionary of <index, list> if there are any errors</returns>
        private Dictionary <int, List <char> > CompareRotors(Rotor[] rotors)
        {
            // dictionary to store the index of the error rotor and the error chars
            Dictionary <int, List <char> > rotorErrors = new Dictionary <int, List <char> >();

            // compare rotors
            for (int i = 1; i < rotors.Length; i++)
            {
                List <char> errors =
                    BasicFunctions.CompareStringsCharacters(rotors[0].RotorString, rotors[i].RotorString);

                if (errors.Count > 0)
                {
                    rotorErrors.Add(i, errors);
                }
            }

            // returns the error dictionary
            return(rotorErrors);
        }
Example #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));
 }
Example #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));
 }