Пример #1
0
        private int[] RinngSettings()
        {
            int[] ringSettings;
            if (ringstellung.Text.Replace(" ", "") == "")
            {
                if (fourthRotorOn.Checked)
                {
                    ringstellung.Text = "1 1 1 1";
                    return(new int[] { 1, 1, 1, 1 });
                }
                else
                {
                    ringstellung.Text = "1 1 1";
                    return(new int[] { 1, 1, 1 });
                }
            }
            string errorMessage = "У вікні положення кілець, мають бути числа від 1 до 26 включно!";

            try
            {
                ringSettings = ringstellung.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(n => int.Parse(n)).ToArray();
            }
            catch
            {
                MessageBox.Show(errorMessage);
                return(null);
            }
            if (fourthRotorOn.Checked)
            {
                if (ringSettings.Length < 4)
                {
                    MessageBox.Show("Положення кілець встановлено не для всіх роторів!\r\nНа разі використовується чотири ротори");
                    return(null);
                }
            }
            else
            {
                if (ringSettings.Length < 3)
                {
                    MessageBox.Show("Положення кілець встановлено не для всіх роторів!\r\nНа разі використовується три ротори");
                    return(null);
                }
            }
            if (!ValidationOfEnigma.AllNumbersIntoInterval(ringSettings))
            {
                MessageBox.Show(errorMessage);
                return(null);
            }
            return(ringSettings);
        }
Пример #2
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);
            }
        }