private void GenKeyButton_Click(object sender, EventArgs e)
 {
     KeyTB.Clear();
     while (KeyTB.TextLength != 32)
     {
         Algorithm_AES.AlgorithmAES aes = new Algorithm_AES.AlgorithmAES();
         byte[] key = aes.GenerateKey();
         for (int i = 0; i < key.Length; i++)
         {
             KeyTB.Text += (char)key[i];
         }
     }
 }
 private void DecButton_Click(object sender, EventArgs e)
 {
     if (OutputRichTextBox.Text == "")
     {
         MessageBox.Show("Введите данные для расшифрования", "Ошибка");
     }
     else
     if (KeyTB.TextLength != 32)
     {
         MessageBox.Show("Длина ключа должна быть равна 32 символам");
     }
     else
     {
         TimeStart();
         Algorithm_AES.AlgorithmAES aes = new Algorithm_AES.AlgorithmAES();
         byte[] key = new byte[KeyTB.TextLength];
         for (int i = 0; i < KeyTB.TextLength; i++)
         {
             key[i] = (byte)bufkey[i];
         }
         byte[] Buffer = aes.Decrypt(resbuf, key, IV);
         OutputRichTextBox.Clear();
         for (int i = 0; i < Buffer.Length; i++)
         {
             if (buf[i] - 1024 > 0)
             {
                 OutputRichTextBox.Text += (char)(Buffer[i] + 1024);
             }
             else
             {
                 OutputRichTextBox.Text += (char)Buffer[i];
             }
         }
         TimeStop();
     }
 }
 private void EncButton_Click(object sender, EventArgs e)
 {
     if (InputRichTextBox.TextLength == 0)
     {
         MessageBox.Show("Введите данные для шифрования", "Ошибка");
     }
     else
     if (KeyTB.TextLength != 32)
     {
         MessageBox.Show("Длина ключа должна быть равна 32 символам");
     }
     else
     if (InputRichTextBox.TextLength % 16 != 0)
     {
         MessageBox.Show("Длина текста должна быть кратна 16");
     }
     else
     {
         TimeStart();
         OutputRichTextBox.Clear();
         Algorithm_AES.AlgorithmAES aes = new Algorithm_AES.AlgorithmAES();
         byte[] Buffer;
         buf = new short[InputRichTextBox.TextLength];
         byte[] res = new byte[InputRichTextBox.TextLength];
         for (short i = 0; i < InputRichTextBox.TextLength; i++)
         {
             buf[i] = (short)InputRichTextBox.Text[i];
         }
         //массив buf необходимый для равботы с символами русского алфавита
         for (short i = 0; i < InputRichTextBox.TextLength; i++)
         {
             if (buf[i] - 1024 > 0)
             {
                 res[i] = (byte)(buf[i] - 1024);
             }
             else
             {
                 res[i] = (byte)buf[i];
             }
         }
         bufkey = new short[KeyTB.TextLength];
         byte[] key = new byte[KeyTB.TextLength];
         for (int i = 0; i < KeyTB.TextLength; i++)
         {
             bufkey[i] = (short)KeyTB.Text[i];
         }
         for (short i = 0; i < KeyTB.TextLength; i++)
         {
             if (bufkey[i] - 1024 > 0)
             {
                 key[i] = (byte)(bufkey[i] - 1024);
             }
             else
             {
                 key[i] = (byte)bufkey[i];
             }
         }
         Buffer = aes.Encrypt(res, key, IV);
         resbuf = Buffer;//запоминаем массив при необходимости расшифрования
         for (int i = 0; i < Buffer.Length; i++)
         {
             OutputRichTextBox.Text += (char)Buffer[i];
         }
         TimeStop();
     }
 }