Esempio n. 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);
        }
        /// <summary>
        /// Display any errors that occured
        /// </summary>
        /// <param name="key">the key provided from POTENTIAL_ERRORS</param>
        /// <param name="errorStr">the error string to append to</param>
        /// <param name="reason">the reason for the error</param>
        /// <param name="isCypher">true if the error is apart of the cypher, false if it is the string</param>
        private void CheckForErrors(POTENTIAL_ERRORS key, ref string errorStr, string reason, bool isCypher = true, bool isLetterError = false)
        {
            if (errors.ContainsKey(key))
            {
                if (errorStr == "")
                {
                    errorStr += "Errors with " + (isCypher ? "Cypher: " + cypher : (isLetterError ? "Letters: " + letters : "String: " + str)) + "\n";
                }

                errorStr += reason + ": " + BasicFunctions.RunThroughList(errors[key]);
            }
        }
Esempio n. 3
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());
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 /// <summary>
 /// Displays the letters that cause the rotor to rotate
 /// </summary>
 /// <returns></returns>
 private string DisplayRotationLetters()
 {
     return(BasicFunctions.RunThroughList(new List <char>(rotorRotateLetters)));
 }
Esempio n. 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));
 }
Esempio n. 7
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));
 }
Esempio n. 8
0
 /// <summary>
 /// Gets the character that corresponds to the letter
 /// </summary>
 /// <param name="c">the letter to reflect</param>
 /// <returns>the reflected character</returns>
 public char GetReflectedCharacter(char c)
 {
     return(ReflectorReflection[BasicFunctions.IndexInAlphabet(c)]);
 }