Exemplo n.º 1
0
 private void decryptFile_Click(object sender, EventArgs e)
 {
     if (currentMode == Mode.Image && image != null)
     {
         HiddenFile f;
         stopwatch.Restart();
         if (random.Checked)
         {
             f = Test1.GetFileFromImage(image);
         }
         else
         {
             if (linear.Checked)
             {
                 f = Test1.GetFileFromImageLinear(image);
             }
             else
             {
                 f = Test1.GetFileFromImage2(image);
             }
         }
         if (f != null)
         {
             stopwatch.Stop();
             OutputConsole.Write(string.Format("Process completed in {0} ms", stopwatch.ElapsedMilliseconds));
             saveFileDialog.FileName = f.filename;
             DialogResult res = saveFileDialog.ShowDialog();
             if (res == System.Windows.Forms.DialogResult.OK)
             {
                 File.WriteAllBytes(saveFileDialog.FileName, f.file);
                 OutputConsole.Write("File saved");
                 if (Path.GetExtension(saveFileDialog.FileName) == ".bmp" || Path.GetExtension(saveFileDialog.FileName) == ".png" || Path.GetExtension(saveFileDialog.FileName) == ".jpg")
                 {
                     ImgPreview p = new ImgPreview(Image.FromFile(saveFileDialog.FileName));
                     p.ShowDialog();
                 }
             }
         }
         else
         {
             //MessageBox.Show("This image doesn't have an encrypted text or an error occurred");
         }
         stopwatch.Reset();
     }
     if (currentMode == Mode.Audio && audio != null)
     {
         HiddenFile file;
         stopwatch.Restart();
         if (random.Checked)
         {
             file = AudioSteganography.DecryptFile(audio);
         }
         else
         {
             if (linear.Checked)
             {
                 file = AudioSteganography.DecryptFileLinear(audio);
             }
             else
             {
                 file = AudioSteganography.DecryptFile2(audio);
             }
         }
         if (file != null)
         {
             stopwatch.Stop();
             OutputConsole.Write(string.Format("Process completed in {0} ms", stopwatch.ElapsedMilliseconds));
             saveFileDialog.FileName = file.filename;
             DialogResult res = saveFileDialog.ShowDialog();
             if (res == System.Windows.Forms.DialogResult.OK)
             {
                 File.WriteAllBytes(saveFileDialog.FileName, file.file);
                 OutputConsole.Write("File saved");
                 if (Path.GetExtension(saveFileDialog.FileName) == ".bmp" || Path.GetExtension(saveFileDialog.FileName) == ".png" || Path.GetExtension(saveFileDialog.FileName) == ".jpg")
                 {
                     ImgPreview p = new ImgPreview(Image.FromFile(saveFileDialog.FileName));
                     p.ShowDialog();
                 }
             }
         }
         stopwatch.Reset();
     }
 }
Exemplo n.º 2
0
 private void encryptFile_Click(object sender, EventArgs e)
 {
     if (currentMode == Mode.Image && image != null)
     {
         loadFileDialog.FileName = "*.*";
         DialogResult res = loadFileDialog.ShowDialog();
         if (res == System.Windows.Forms.DialogResult.OK)
         {
             file     = File.ReadAllBytes(loadFileDialog.FileName);
             filename = loadFileDialog.SafeFileName;
             OutputConsole.Write("Added File to buffer");
             Bitmap encrypted;
             stopwatch.Restart();
             if (random.Checked)
             {
                 encrypted = Test1.InsertFileToImage(image, file, filename);
             }
             else
             {
                 if (linear.Checked)
                 {
                     encrypted = Test1.InsertFileToImageLinear(image, file, filename);
                 }
                 else
                 {
                     encrypted = Test1.InsertFileToImage2(image, file, filename);
                 }
             }
             if (encrypted != null)
             {
                 stopwatch.Stop();
                 OutputConsole.Write(string.Format("Process completed in {0} ms", stopwatch.ElapsedMilliseconds));
                 saveDialog.FileName = "*.*";
                 DialogResult res2 = saveDialog.ShowDialog();
                 if (res2 == System.Windows.Forms.DialogResult.OK)
                 {
                     encrypted.Save(saveDialog.FileName);
                     OutputConsole.Write("Image saved");
                 }
             }
             stopwatch.Reset();
         }
     }
     if (currentMode == Mode.Audio && audio != null)
     {
         loadFileDialog.FileName = "*.*";
         DialogResult res = loadFileDialog.ShowDialog();
         if (res == System.Windows.Forms.DialogResult.OK)
         {
             byte[] file;
             stopwatch.Restart();
             if (random.Checked)
             {
                 file = AudioSteganography.EncryptFile(audio, File.ReadAllBytes(loadFileDialog.FileName), loadFileDialog.SafeFileName);
             }
             else
             {
                 if (linear.Checked)
                 {
                     file = AudioSteganography.EncryptFileLinear(audio, File.ReadAllBytes(loadFileDialog.FileName), loadFileDialog.SafeFileName);
                 }
                 else
                 {
                     file = AudioSteganography.EncryptFile2(audio, File.ReadAllBytes(loadFileDialog.FileName), loadFileDialog.SafeFileName);
                 }
             }
             if (file != null)
             {
                 stopwatch.Stop();
                 OutputConsole.Write(string.Format("Process completed in {0} ms", stopwatch.ElapsedMilliseconds));
                 DialogResult res2 = saveWav.ShowDialog();
                 if (res2 == System.Windows.Forms.DialogResult.OK)
                 {
                     File.WriteAllBytes(saveWav.FileName, file);
                     OutputConsole.Write("Wav file saved");
                 }
             }
             stopwatch.Reset();
         }
     }
 }