private void StartEncryption(object sender, RoutedEventArgs e)
 {
     if (uploadedImg.Source == null)
     {
         ShowMessageBox("Зображення для зашифровки не завантажено!", "Warning");
         return;
     }
     window.Cursor = Cursors.Wait;
     try
     {
         if (Encryption.currentAlg == 0)
         {
             processedImg.Source = TranspositionAlg.Encrypt(uploadedImg.Source as BitmapSource);
         }
         else
         {
             processedImg.Source = SymetricAlg.RunAlg(uploadedImg.Source as BitmapSource, 0);
         }
     }
     catch (Exception err)
     {
         ShowMessageBox(err.Message.ToString(), "Error");
         window.Cursor = Cursors.Arrow;
         return;
     }
     decrypted     = false;
     window.Cursor = Cursors.Arrow;
 }
        private void GenerateRng(object sender, RoutedEventArgs e)
        {
            window.Cursor = Cursors.Wait;
            int bytesPerPixel = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource);

            if (Encryption.currentAlg == 0)
            {
                TranspositionAlg.Generate((sender as Button).Name, Int32.Parse((sender as Button).Uid), null);
            }
            else
            {
                SymetricAlg.Generate(null);
            }
            window.Cursor = Cursors.Arrow;
        }
        private void GeneratePass(object sender, RoutedEventArgs e)
        {
            window.Cursor = Cursors.Wait;
            if (currentAction == 1)
            {
                decrypted = false;
            }
            int bytesPerPixel = Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource);

            if (Encryption.currentAlg == 0)
            {
                TranspositionAlg.Generate((sender as PasswordBox).Name, Int32.Parse((sender as PasswordBox).Uid), (sender as PasswordBox).Password);
            }
            else
            {
                SymetricAlg.Generate((sender as PasswordBox).Password);
            }
            window.Cursor = Cursors.Arrow;
        }
 private void StartDecryption(object sender, RoutedEventArgs e)
 {
     if (decrypted)
     {
         ShowMessageBox("Ви вже розшифровували це зображення!\nЗашифруйте знову!", "Warning");
         return;
     }
     if (Encryption.algParams.Count < (Encryption.currentAlg == 0 ? 5 : 4))
     {
         ShowMessageBox("Ключ розшифровки не завантажено!", "Warning");
         return;
     }
     if (uploadedImg.Source == null)
     {
         ShowMessageBox("Зображення для розшифровки не завантажено!", "Warning");
         return;
     }
     window.Cursor = Cursors.Wait;
     try
     {
         var image = currentAction == 0 ? processedImg.Source as BitmapSource : uploadedImg.Source as BitmapSource;
         if (Encryption.currentAlg == 0)
         {
             processedImg.Source = TranspositionAlg.Decrypt(image);
         }
         else
         {
             processedImg.Source = SymetricAlg.RunAlg(image, 1);
         }
     }
     catch (Exception err)
     {
         ShowMessageBox(err.Message.ToString(), "Error");
         window.Cursor = Cursors.Arrow;
         return;
     }
     decrypted     = true;
     window.Cursor = Cursors.Arrow;
 }
        private void StartExport(object sender, RoutedEventArgs e)
        {
            if (processedImg.Source == null)
            {
                ShowMessageBox("Немає зображення для експорту!", "Warning");
                return;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "BMP Files|*.bmp";
            saveFileDialog.CreatePrompt     = true;
            saveFileDialog.OverwritePrompt  = true;
            saveFileDialog.RestoreDirectory = true;
            if ((bool)saveFileDialog.ShowDialog())
            {
                window.Cursor = Cursors.Wait;
                try
                {
                    var encoder = new BmpBitmapEncoder();

                    encoder.Frames.Add(BitmapFrame.Create((processedImg.Source as BitmapSource)));
                    using (FileStream stream = File.Open(saveFileDialog.FileName, FileMode.Create))
                    {
                        encoder.Save(stream);
                        stream.Close();
                    }
                    if (currentAction == 0)
                    {
                        string key = Encryption.currentAlg.ToString() + ";";
                        key = Convert.ToBase64String(Encoding.Unicode.GetBytes(
                                                         key + (Encryption.currentAlg == 0 ? TranspositionAlg.Export() : SymetricAlg.Export())));
                        using (StreamWriter file = new StreamWriter(saveFileDialog.FileName + ".txt", false))
                        {
                            file.Write(key);
                            file.Close();
                        }
                        this.Cursor = Cursors.Arrow;
                        ShowMessageBox("Файл розшифровки: \n(" + saveFileDialog.FileName + ".txt) \nуспішно створено!", "Info");
                    }
                    window.Cursor = Cursors.Arrow;
                }
                catch (Exception err)
                {
                    ShowMessageBox(err.Message.ToString(), "Error");
                    window.Cursor = Cursors.Arrow;
                    return;
                }
            }
        }