Esempio n. 1
0
        private void OnSelectNewFileButtonClicked(object sender, RoutedEventArgs e)
        {
            string key = GetKeyFromUser();

            if (String.IsNullOrWhiteSpace(key))
            {
                MessageBox.Show(this, "Ключ не был введён!!!");
                return;
            }
            key = key.Trim();

            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.CheckFileExists = true;
            fileDialog.Title           = "Выберите файл";
            fileDialog.DefaultExt      = ".txt";
            fileDialog.Filter          = "Text documents (.txt)|*.txt";
            Nullable <bool> result = fileDialog.ShowDialog();

            if (result == false)
            {
                MessageBox.Show(this, "Файл не выбран!!");
                return;
            }

            orginalText = File.ReadAllText(fileDialog.FileName, Encoding.Default);

            VigenereCipher cipher = new VigenereCipher(alphabet);

            TextPanel.Text = cipher.Decrypt(orginalText, key);
        }
Esempio n. 2
0
        private void OnEncryptButtomClicked(object sender, RoutedEventArgs e)
        {
            string text = TextForEncryption.Text.Trim();

            if (String.IsNullOrWhiteSpace(text))
            {
                MessageBox.Show(this, "Нет исходного текста!!!");
                return;
            }

            string key = GetKeyFromUser();

            if (String.IsNullOrWhiteSpace(key))
            {
                MessageBox.Show(this, "Ключ не был введён!!!");
                return;
            }
            key = key.Trim();

            VigenereCipher cipher        = new VigenereCipher(alphabet);
            string         encryptedText = cipher.Encrypt(text, key);

            SaveFileDialog fileDialog = new SaveFileDialog();

            fileDialog.FileName   = "Encypted";
            fileDialog.DefaultExt = ".txt";
            fileDialog.Filter     = "Text documents (.txt)|*.txt";
            Nullable <bool> result = fileDialog.ShowDialog();

            if (result == true)
            {
                File.WriteAllText(fileDialog.FileName, encryptedText, Encoding.Default);
            }
        }
Esempio n. 3
0
        private void OnChangeKeyButtonClicked(object sender, RoutedEventArgs e)
        {
            if (orginalText == String.Empty)
            {
                MessageBox.Show(this, "Нет исходного текста!!!");
                return;
            }

            string key = GetKeyFromUser();

            if (String.IsNullOrWhiteSpace(key))
            {
                MessageBox.Show(this, "Ключ не был введён!!!");
                return;
            }
            key = key.Trim();

            VigenereCipher cipher = new VigenereCipher(alphabet);

            TextPanel.Text = cipher.Decrypt(orginalText, key);
        }
Esempio n. 4
0
        private void OnEncryptDocumentButtonClicked(object sender, RoutedEventArgs e)
        {
            string text = DocumentText.Text.Trim();

            if (String.IsNullOrWhiteSpace(text))
            {
                MessageBox.Show(this, "Нет исходного текста!!!");
                return;
            }

            string key = GetKeyFromUser();

            if (String.IsNullOrWhiteSpace(key))
            {
                MessageBox.Show(this, "Ключ не был введён!!!");
                return;
            }
            key = key.Trim();

            VigenereCipher cipher = new VigenereCipher(alphabet);

            DocumentText.Text = cipher.Encrypt(text, key);
        }