Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 private void ChipherType2D(object sender, RoutedEventArgs e)
 {
     Encryption.algParams[3] = 2;
     DrawSettings();
     if (Encryption.currentAlg == 0 && uploadedImg.Source != null)
     {
         TranspositionAlg.SetKey(Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource));
     }
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
        private void OpenImg(object sender, RoutedEventArgs e)
        {
            var openFile = new OpenFileDialog();

            openFile.Filter           = "Image Files(*.BMP;*.JPG;*.GIF;*.PNG;)|*.BMP;*.JPG;*.GIF;*.PNG;";
            openFile.RestoreDirectory = true;
            if (openFile.ShowDialog() == true)
            {
                dynamic decoder = null;
                try
                {
                    var streamSource = new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    switch (new FileInfo(openFile.FileName).Extension)
                    {
                    case ".jpg":
                        decoder = new JpegBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".png":
                        decoder = new PngBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".bmp":
                        decoder = new BmpBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;

                    case ".gif":
                        decoder = new GifBitmapDecoder(streamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        break;
                    }
                    uploadedImg.Source = decoder.Frames[0];
                }
                catch (Exception err)
                {
                    ShowMessageBox(err.Message.ToString(), "Error");
                    return;
                }
                imagePath.Text = openFile.FileName;
                keyPath.Text   = null;
                SetParams();
                DrawSettings();
                if (Encryption.currentAlg == 0 && uploadedImg.Source != null)
                {
                    TranspositionAlg.SetKey(Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource));
                }
                decrypted = false;
            }
        }
Ejemplo n.º 5
0
        private void SetParams()
        {
            switch (Encryption.currentAlg)
            {
            case 0:
                Encryption.algParams = new List <int>()
                {
                    0, 1, 256, 2
                };
                if (uploadedImg.Source != null)
                {
                    TranspositionAlg.SetKey(Encryption.CountBytesPerPixel(uploadedImg.Source as BitmapSource));
                }
                break;

            case 1:
                Encryption.algParams = new List <int>()
                {
                    0, 64, 8
                };
                break;

            case 2:
                Encryption.algParams = new List <int>()
                {
                    0, 128, 8
                };
                break;

            case 3:
                Encryption.algParams = new List <int>()
                {
                    0, 128, 16
                };
                break;

            case 4:
                Encryption.algParams = new List <int>()
                {
                    0, 40, 8
                };
                break;
            }
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
        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;
                }
            }
        }