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 }); }
private static IEnigmaSettings GetSettingsKey(byte[] key) { string keyString = Encoding.Unicode.GetString(key); string[] parts = keyString.Split(new char[] { KeySeperator }, StringSplitOptions.None); if (parts.Length != KeyParts) { throw new ArgumentException("Incorrect number of key parts.", nameof(key)); } IEnigmaReflector reflector = ParseEnigmaReflectorNumber(parts[0]); IDictionary <EnigmaRotorPosition, EnigmaRotorNumber> rotorNumbers = ParseEnigmaRotorNumbers(parts[1]); IDictionary <EnigmaRotorPosition, int> rings = ParseEnigmaRings(parts[2]); IReadOnlyDictionary <EnigmaRotorPosition, IEnigmaRotor> list = new Dictionary <EnigmaRotorPosition, IEnigmaRotor> { { EnigmaRotorPosition.Fastest, new EnigmaRotor() { RotorNumber = rotorNumbers[EnigmaRotorPosition.Fastest], RingPosition = rings[EnigmaRotorPosition.Fastest] } }, { EnigmaRotorPosition.Second, new EnigmaRotor() { RotorNumber = rotorNumbers[EnigmaRotorPosition.Second], RingPosition = rings[EnigmaRotorPosition.Second] } }, { EnigmaRotorPosition.Third, new EnigmaRotor() { RotorNumber = rotorNumbers[EnigmaRotorPosition.Third], RingPosition = rings[EnigmaRotorPosition.Third] } }, }; EnigmaRotors rotors = new(list); EnigmaPlugboard plugboard = ParsePlugboard(parts[3]); return(new EnigmaSettings() { Reflector = reflector, Rotors = rotors, Plugboard = plugboard }); }