Exemplo n.º 1
0
        private EncryptionStrategy GetEncryptionStrategy(Mode mode = Mode.Encrypt)
        {
            EncryptionStrategy result = null;
            String             input  = inputText.Text;

            switch (algorithmDrowdown.Text)
            {
            case "Железнодорожная изгородь":
                try
                {
                    int key = int.Parse(keyInput.Text);
                    result = new EncryptionStrategies.RailwayFenceEncryptionStrategy(input, key);
                }
                catch (FormatException err)
                {
                    throw new ArgumentException("Ключ должен быть числом");
                }
                break;

            case "\"Ключевая фраза\"":
                result = new EncryptionStrategies.PassPhraseEncryptionStrategy(input, keyInput.Text); break;

            case "Метод поворачивающейся решетки":
                GridForm gridForm = new GridForm();
                if (gridForm.ShowDialog() == DialogResult.OK)
                {
                    result = new EncryptionStrategies.RotatingGridEncryptionStrategy(input, gridForm.GetGrid());
                }
                break;

            case "Шифр Вижинера":
                result = new EncryptionStrategies.VigenereEncryptionStrategy(input, keyInput.Text); break;

            case "Криптосистема Рабина":
                if (rabinKeyForm == null)
                {
                    rabinKeyForm = new RabinKeyForm(mode);
                }
                rabinKeyForm.Mode = mode;
                if (rabinKeyForm.ShowDialog() == DialogResult.OK)
                {
                    result = new EncryptionStrategies.RabinEncryptionStrategy(input, mode == Mode.Encrypt ? rabinKeyForm.PublicKey : rabinKeyForm.PrivateKey);
                }
                break;

            default:
                throw new ArgumentException("Выберите метод шифрования");
            }

            return(result);
        }
Exemplo n.º 2
0
        private EncryptionStrategy GetEncryptionStrategy(Mode mode = Mode.Encrypt)
        {
            EncryptionStrategy result = null;
            String input = inputText.Text;

            switch (algorithmDrowdown.Text)
            {
                case "Железнодорожная изгородь":
                    try
                    {
                        int key = int.Parse(keyInput.Text);
                        result = new EncryptionStrategies.RailwayFenceEncryptionStrategy(input, key);
                    }
                    catch (FormatException err)
                    {
                        throw new ArgumentException("Ключ должен быть числом");
                    }
                    break;
                case "\"Ключевая фраза\"":
                    result = new EncryptionStrategies.PassPhraseEncryptionStrategy(input, keyInput.Text); break;
                case "Метод поворачивающейся решетки":
                    GridForm gridForm = new GridForm();
                    if (gridForm.ShowDialog() == DialogResult.OK)
                    {
                        result = new EncryptionStrategies.RotatingGridEncryptionStrategy(input, gridForm.GetGrid());
                    } break;
                case "Шифр Вижинера":
                    result = new EncryptionStrategies.VigenereEncryptionStrategy(input, keyInput.Text); break;
                case "Криптосистема Рабина":
                    if (rabinKeyForm == null)
                    {
                        rabinKeyForm = new RabinKeyForm(mode);
                    }
                    rabinKeyForm.Mode = mode;
                    if (rabinKeyForm.ShowDialog() == DialogResult.OK)
                    {
                        result = new EncryptionStrategies.RabinEncryptionStrategy(input, mode == Mode.Encrypt ? rabinKeyForm.PublicKey : rabinKeyForm.PrivateKey);
                    } break;
                default:
                    throw new ArgumentException("Выберите метод шифрования");
            }

            return result;
        }