Ejemplo n.º 1
0
 public static void DecryptFile(string fileName, string key, CipherType cipherType, int n)
 {
     try
     {
         string cipherText   = File.ReadAllText(fileName);
         string originalText = ParallelCipher.Decrypt(cipherText, key, cipherType, n);
         File.WriteAllText(fileName, originalText);
         MessageBox.Show("The file has been decrypted");
     }
     catch (UnauthorizedAccessException)
     {
         MessageBox.Show("Access error");
     }
     catch (DirectoryNotFoundException)
     {
         MessageBox.Show("Didectory not found");
     }
     catch (FileNotFoundException)
     {
         MessageBox.Show("File not found");
     }
     catch (Exception e)
     {
         MessageBox.Show("Unexpected error: " + e.Message);
     }
 }
Ejemplo n.º 2
0
        private void button3_Click(object sender, EventArgs e)
        {
            if ((textBox3.Text == "") && (label4.Text == "Файл не выбран") || firstUsing)
            {
                MessageBox.Show("Введите текст для дешифрования");
                return;
            }
            if (!int.TryParse(textBox1.Text, out n))
            {
                MessageBox.Show("Некорректное число рабочих");
                return;
            }
            if (n <= 0)
            {
                MessageBox.Show("Число рабочих должно быть больше нуля");
                return;
            }

            CipherType c;

            if (cipherType == "DES")
            {
                c = CipherType.DES;
            }
            else
            {
                c = CipherType.AES;
            }
            if (fileName != "")
            {
                FileCryptor.DecryptFile(fileName, key, c, n);
                fileName    = "";
                label4.Text = "Файл не выбран";
            }
            else
            {
                textBox4.Text = ParallelCipher.Decrypt(plainText, key, c, n);
            }
        }