public Rotor(RotorName name, int startingPosition) { _name = name; _startingPosition = startingPosition; _rotorPosition = startingPosition; _turnoverPositions = CalculateTurnoverPositions(_name); }
private int[] CalculateTurnoverPositions(RotorName name) { if (_name == RotorName.I) { return(new[] { 18 }); } else if (_name == RotorName.II) { return(new[] { 6 }); } else if (_name == RotorName.III) { return(new[] { 23 }); } else if (_name == RotorName.IV) { return(new[] { 11 }); } else if (_name == RotorName.V) { return(new[] { 1 }); } else { return(new[] { 1, 14 }); } }
public Rotor(RotorName name) : base(name.ToString(), Wiring.Current.Rotors[(int)name]) { _rotorName = name; _notchRingInitializer = Wiring.Current.Notches[(int)_notchRingName]; InitNotches(); }
public Rotor(RotorName name, params int[] notches) : base(name.ToString(), Constants.Rotors[(int)name]) { RotorName = name; foreach (int i in notches) { _contacts[i].Notch = true; } }
public override int GetHashCode() { unchecked { int result = 7411; result = (result * 733) ^ RotorName.GetHashCode(); result = (result * 733) ^ AlphabetRingPosition; result = (result * 733) ^ NotchRingName.GetHashCode(); result = (result * 733) ^ NotchRingPosition; return(result); } }
private void CheckConfiguration() { if ((CbxRotor1.Text.Length != 0) && (CbxRotor2.Text.Length != 0)) { if ((CbxRotor1.Text == CbxRotor2.Text)) { MessageBox.Show("Rotors 1 and 2 cannot match!"); } } if ((CbxRotor2.Text.Length != 0) && (CbxRotor3.Text.Length != 0)) { if ((CbxRotor2.Text == CbxRotor3.Text)) { MessageBox.Show("Rotors 2 and 3 cannot match!"); } } if ((CbxRotor1.Text.Length != 0) && (CbxRotor3.Text.Length != 0)) { if (CbxRotor1.Text == CbxRotor3.Text) { MessageBox.Show("Rotors 1 and 3 cannot match!"); } } if ((CbxRotor1.Text.Length != 0) && (CbxRotor2.Text.Length != 0) && (CbxRotor3.Text.Length != 0)) { if ((CbxStartPos1.Text.Length != 0) && (CbxStartPos2.Text.Length != 0) && (CbxStartPos3.Text.Length != 0)) { RotorName rotor1 = CreateRotor(CbxRotor1.Text); RotorName rotor2 = CreateRotor(CbxRotor2.Text); RotorName rotor3 = CreateRotor(CbxRotor3.Text); int startPos1 = int.Parse(CbxStartPos1.Text); int startPos2 = int.Parse(CbxStartPos2.Text); int startPos3 = int.Parse(CbxStartPos3.Text); _enigmaMachine = new EnigmaMachine(new[] { rotor1, rotor2, rotor3 }, new[] { startPos1, startPos2, startPos3 }); EnablePlugs(); BtnConfigure.Enabled = true; return; } } RtbContent.Enabled = false; RtbOutput.Enabled = false; DisablePlugs(); BtnConfigure.Enabled = false; BtnEncode.Enabled = false; }
public static RotorName?GetRotorNameFromString(this string s) { RotorName result = RotorName.RotorA; if (s.Contains("Rotor")) { if (Enum.TryParse <RotorName>(s, out result)) { return(result); } } string check = string.Format("Rotor{0}", s); if (Enum.TryParse <RotorName>(check, out result)) { return(result); } return(null); }
public RotorSetting(RotorName name, int ring) { Name = name; RingSetting = ring; }
public Rotor this[RotorName rotName] { get { return(this.FirstOrDefault(r => r.RotorName == rotName)); } }
public override string ToString() { return(string.Format("{0} {1} {2} {3}", RotorName.GetRotorName(), AlphabetRingPosition, NotchRingName.GetNotchRingName(), Rotor.PositionToSetting(NotchRingPosition))); }
public static Settings Random(MachineType m) { Machine mach = new Machine(m); Settings result = new Settings(); result.MachineType = m; result.ReflectorType = mach.AvailableReflectors[RandomUtil._rand.Next(mach.AvailableReflectors.Count)].ReflectorType; List <RotorName> availableNames = mach.AvailableRotors.Select(r => r.RotorName).ToList(); if (m == MachineType.M4K) { availableNames.Remove(RotorName.Beta); availableNames.Remove(RotorName.Gamma); if (RandomUtil._rand.Next(2) == 1) { result.Rotors.Add(new RotorSetting { Name = RotorName.Beta, RingSetting = RandomUtil._rand.Next(Constants.ALPHABET.Length) }); } else { result.Rotors.Add(new RotorSetting { Name = RotorName.Gamma, RingSetting = RandomUtil._rand.Next(Constants.ALPHABET.Length) }); } } for (int i = 0; i < 3; i++) { RotorName name = availableNames[RandomUtil._rand.Next(availableNames.Count)]; result.Rotors.Add(new RotorSetting { Name = name, RingSetting = RandomUtil._rand.Next(Constants.ALPHABET.Length) }); availableNames.Remove(name); } List <Tuple <string, double> > letters = new List <Tuple <string, double> >(); foreach (char c in Constants.ALPHABET) { letters.Add(new Tuple <string, double>(c.ToString(), RandomUtil._rand.NextDouble())); } letters.Sort((a, b) => a.Item2.CompareTo(b.Item2)); for (int i = 0; i < 10; i++) { var f = letters.First(); var l = letters.Last(); string a = f.Item1; string b = l.Item1; if (a.CompareTo(b) > 0) { result.Plugs.Add(new PlugSetting { LetterA = b, LetterB = a }); } else { result.Plugs.Add(new PlugSetting { LetterA = a, LetterB = b }); } letters.Remove(f); letters.Remove(l); } result.Plugs.Sort((a, b) => a.ToString().CompareTo(b.ToString())); if (result.MachineType != MachineType.M3) { result.Grund = RandomUtil.GenerateSequence(4, Constants.ALPHABET, false, false); if (result.MachineType == MachineType.M3K) { result.Grund = result.Grund.Substring(0, 3); } result.Kenngruppen.Clear(); } else { result.Grund = string.Empty; result.Kenngruppen.Clear(); for (int i = 0; i < 4; i++) { result.Kenngruppen.Add(RandomUtil.GenerateSequence(3, Constants.ALPHABET, false, false)); } } return(result); }
public static string GetRotorName(this RotorName source) { return(source.ToString().Last().ToString()); }