コード例 #1
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);
            }
        }
コード例 #2
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);
        }