Пример #1
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());
            }
        }