Пример #1
0
        private void AddReflector(string filename)
        {
            string[] file         = File.ReadAllLines(filename);
            string   errorMessage = "Файл пошкоджено!";

            if (file.Length < 2)
            {
                MessageBox.Show(errorMessage);
                return;
            }
            string wiring = file[1].Replace(" ", "").ToUpper();

            if (wiring.Length != 26)
            {
                return;
            }
            if (!ValidationOfEnigma.BelongAlphabet(wiring))
            {
                MessageBox.Show(errorMessage);
                return;
            }
            if (ValidationOfEnigma.SymbolsRepeated(wiring))
            {
                MessageBox.Show(errorMessage);
                return;
            }
            reflectors.Add(file[0], wiring);
            listReflectors.Items.Add(file[0]);
            reflectorComboBox.Items.Add(file[0]);
        }
Пример #2
0
        private string SteckerSettings()
        {
            string steckerSettings = steckerverbindungen.Text.Replace(" ", "").ToUpper();

            if (steckerSettings == "")
            {
                return(steckerSettings);
            }

            if (!ValidationOfEnigma.BelongAlphabet(steckerSettings))
            {
                MessageBox.Show("Cbvdjks");
                return(null);
            }

            if (steckerSettings.Length > 20)
            {
                MessageBox.Show("10");
                return(null);
            }

            if (steckerSettings.Length % 2 != 0)
            {
                MessageBox.Show("Парне");
                return(null);
            }

            if (ValidationOfEnigma.SymbolsRepeated(steckerSettings))
            {
                MessageBox.Show("Повторення");
                return(null);
            }

            return(steckerSettings);
        }
Пример #3
0
        private void AddRotor(string filename)
        {
            string[] file         = File.ReadAllLines(filename);
            string   errorMessage = "Файл пошкоджено!";

            if (file.Length < 3)
            {
                MessageBox.Show(errorMessage);
                return;
            }
            string wiring = file[1].Replace(" ", "").ToUpper();

            int[] notchs;
            if (wiring.Length == 26 && file[2].Replace(" ", "") != "")
            {
                if (!ValidationOfEnigma.BelongAlphabet(wiring))
                {
                    MessageBox.Show(errorMessage);
                    return;
                }
                if (ValidationOfEnigma.SymbolsRepeated(wiring))
                {
                    MessageBox.Show(errorMessage);
                    return;
                }
                try
                {
                    notchs = file[2].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(n => int.Parse(n)).ToArray();
                }
                catch
                {
                    MessageBox.Show(errorMessage);
                    return;
                }
                if (!ValidationOfEnigma.AllNumbersIntoInterval(notchs))
                {
                    MessageBox.Show(errorMessage);
                    return;
                }

                try
                {
                    if (notchs.Length > 1)
                    {
                        rotors.Add(file[0], new Rotor()
                        {
                            Wiring = wiring, Notch = notchs[0] - 1, Notch2 = notchs[1] - 1
                        });
                    }
                    else
                    {
                        rotors.Add(file[0], new Rotor()
                        {
                            Wiring = wiring, Notch = notchs[0] - 1
                        });
                    }
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Ротор з таким ключем уже існує!");
                    return;
                }
                listRotors.Items.Add(file[0]);
                rightRotorComboBox.Items.Add(file[0]);
                middleRotorComboBox.Items.Add(file[0]);
                leftRotorComboBox.Items.Add(file[0]);
                rotor4ComboBox.Items.Add(file[0]);
            }
            else
            {
                MessageBox.Show(errorMessage);
            }
        }