public static EnigmaSettings Generate()
        {
            // Reflector
            IEnigmaReflector reflector = EnigmaReflectorGenerator.Generate();

            // Rotor Settings
            IEnigmaRotors rotors = EnigmaRotorGenerator.Generate();

            // Plugboard
            IEnigmaPlugboard plugboard = EnigmaPlugboardGenerator.Generate();

            return(new EnigmaSettings()
            {
                Reflector = reflector, Rotors = rotors, Plugboard = plugboard
            });
        }
Exemplo n.º 2
0
        private static string PlugboardString(IEnigmaPlugboard plugboard)
        {
            StringBuilder key = new();
            IReadOnlyDictionary <char, char> substitutions = plugboard.Substitutions();

            foreach (KeyValuePair <char, char> pair in substitutions)
            {
                key.Append(pair.Key);
                key.Append(pair.Value);
                key.Append(KeyDelimiter);
            }

            if (substitutions.Count > 0 &&
                key.Length > 0)
            {
                key.Remove(key.Length - 1, 1);
            }

            return(key.ToString());
        }