private void loadImage_Click(object sender, EventArgs e) { loadDialog.FileName = "*.*"; DialogResult res = loadDialog.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { if (image != null) { image.Dispose(); } string ext = Path.GetExtension(loadDialog.FileName); if (ext == ".png" || ext == ".bmp" || ext == ".jpg") { try { image = Image.FromFile(loadDialog.FileName); imageBox.Image = image; OutputConsole.Write(string.Format("Image loaded \nTotal pixels = {0}", image.Width * image.Height)); OutputConsole.Write(string.Format("Maximum file size for this image = {0} - (file size digits + file name character count) bytes", FileSizeFormatProvider.GetFileSize((image.Width * image.Height) - 2))); currentMode = Mode.Image; audio = null; audioLabel.Visible = false; } catch { image = null; imageBox.Image = null; } } } }
private void linear_CheckedChanged(object sender, EventArgs e) { if (linear.Checked) { OutputConsole.Write("Using linear steganography algorithm (Fastest)"); } }
private void loadWavFile_Click(object sender, EventArgs e) { DialogResult res = loadWav.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { audio = File.ReadAllBytes(loadWav.FileName); WavAudio wav = new WavAudio(audio); if (wav.data != null) { OutputConsole.Write(string.Format("Audio loaded \nSamples found: {0}", wav.totalSamples)); OutputConsole.Write(string.Format("Maximum file size for this file = {0} - (file size digits + file name character count) bytes", FileSizeFormatProvider.GetFileSize(wav.bytesAvailable))); currentMode = Mode.Audio; if (image != null) { image.Dispose(); } image = null; imageBox.Image = null; audioLabel.Text = string.Format("Using Wav File: {0}", loadWav.SafeFileName); audioLabel.Visible = true; } else { audio = null; } } }
private static void EncodeMessageLinear(ref Bitmap img, string text) { int maxLinear = img.Width * img.Height; string pass = string.Format("{0}x{1}={2}", img.Width, img.Height, maxLinear); AESEncrypt encrypt = new AESEncrypt(); int c = 0; string encrypted = encrypt.EncryptString(text, pass); OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted)); OutputConsole.Write("Processing image..."); if (encrypted.Length < maxLinear) { for (int i = 0; i < encrypted.Length; i++) { Point point = LinearIndexToPoint(i, img.Width, img.Height); Color pixel = img.GetPixel(point.X, point.Y); char letter = encrypted[i]; int value = Convert.ToInt32(letter); Color n = EncodePixel(pixel, value); img.SetPixel(point.X, point.Y, n); c = i; } //Null value placed at the end to indicate end of text - or using 255 for better hiding Point pointEnd = LinearIndexToPoint(c, img.Width, img.Height); Color pixelEnd = img.GetPixel(pointEnd.X, pointEnd.Y); img.SetPixel(pointEnd.X, pointEnd.Y, EncodePixel(pixelEnd, 0)); OutputConsole.Write("Finished embedding encrypted text"); } else { OutputConsole.Write("Error: Image size doesn't support encrypted text size"); img = null; } }
public static string GetDecryptedTextFromImageLinear(Image image) { Bitmap img = new Bitmap(image); int maxLinear = image.Width * image.Height; string pass = string.Format("{0}x{1}={2}", image.Width, image.Height, maxLinear); AESEncrypt encrypt = new AESEncrypt(); string text = string.Empty; int value = 0; int i = 0; OutputConsole.Write("Processing image..."); do { Point point = LinearIndexToPoint(i, image.Width, image.Height); Color pixel = img.GetPixel(point.X, point.Y); value = DecodePixel(pixel); i++; if (value != 255) { text += Convert.ToChar(value); } } while (value != 255); try { OutputConsole.Write(string.Format("String found: \n{0}", text)); OutputConsole.Write("Decrypting text..."); return(encrypt.DecryptString(text, pass)); } catch (Exception e) { OutputConsole.Write("Error: Text not found"); Console.WriteLine(e.Message); return(null); } }
private void random_CheckedChanged(object sender, EventArgs e) { if (random.Checked) { OutputConsole.Write("Using random steganography algorithm (Requires prime number generation, slow for huge images/wav files, once the generator has reached the needed number it can process files quickly)"); } //OutputConsole.Write("Using random steganography algorithm (Not recommended for huge files or text near 60% image pixels or more than 10% of available bytes in wav files)"); }
private void randomM2_CheckedChanged(object sender, EventArgs e) { //Removed if (randomM2.Checked) { OutputConsole.Write("Using random method 2 steganography algorithm (Poor performance on small files, but better performance than random using bigger files) \nWorks only with files..."); } }
public Form1() { InitializeComponent(); OutputConsole.Bind(console); random.Checked = true; currentMode = Mode.Image; stopwatch = new Stopwatch(); }
private void encryptButton_Click(object sender, EventArgs e) { if (currentMode == Mode.Image && image != null) { Bitmap encrypted; if (random.Checked || randomM2.Checked) { encrypted = Test1.InsertEncryptedTextToImage(image, textBox.Text); } else { encrypted = Test1.InsertEncryptedTextToImageLinear(image, textBox.Text); } if (encrypted != null) { saveDialog.FileName = "*.*"; DialogResult res = saveDialog.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { encrypted.Save(saveDialog.FileName); OutputConsole.Write("Image saved"); } } } if (currentMode == Mode.Audio && audio != null) { byte[] file; if (random.Checked) { file = AudioSteganography.EncryptText(audio, textBox.Text); } else { file = AudioSteganography.EncryptTextLinear(audio, textBox.Text); } if (file != null) { DialogResult res = saveWav.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { File.WriteAllBytes(saveWav.FileName, file); OutputConsole.Write("Wav file saved"); } } } }
public static byte[] EncryptTextLinear(byte[] wav, string text) { WavAudio audio = new WavAudio(wav); uint value = 0; string pass = string.Format(audio.bitsPerSample.ToString()); AESEncrypt encrypt = new AESEncrypt(); string encrypted = encrypt.EncryptString(text, pass); OutputConsole.Write(string.Format("Text encrypted \n{0}", encrypted)); if (encrypted.Length <= Math.Floor((double)(audio.totalSamples / 8))) { uint n = 0; OutputConsole.Write("Seed generated"); OutputConsole.Write("Processing wav file..."); for (int i = 0; i < encrypted.Length; i++) { value = encrypted[i]; for (int x = 0; x < 8; x++) { uint sample = n; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; n++; } } value = 0; for (int x = 0; x < 8; x++) { uint sample = n; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; n++; } audio.Save(); OutputConsole.Write(string.Format("Text encrypted... used {0} samples", encrypted.Length * 8)); OutputConsole.Write("Saving wav file"); return(audio.data); } else { return(null); } }
public WavAudio(byte[] data) { this.data = data; Array.Copy(data, 0, header, 0, 0x2E); channels = BitConverter.ToUInt16(data, 0x16); bitsPerSample = BitConverter.ToUInt16(data, 0x22); if (bitsPerSample == 8 || bitsPerSample == 16 || bitsPerSample == 24 || bitsPerSample == 32) { totalSamples = (BitConverter.ToUInt32(data, 0x2A) / channels) / (bitsPerSample / 8); samples = new uint[totalSamples]; int i = 0; for (int n = 0; n < totalSamples; n++) { switch (bitsPerSample) { case 8: samples[n] = data[start + i]; break; case 16: default: samples[n] = BitConverter.ToUInt16(data, start + i); break; case 24: samples[n] = BitConverter.ToUInt32(data, start + i) & 0xFFFFFF; break; case 32: samples[n] = BitConverter.ToUInt32(data, start + i); break; } i += (int)(bitsPerSample / 8); } bytesAvailable = (long)Math.Floor((double)(totalSamples / 8)); } else { OutputConsole.Write("This file is incompatible, bits per sample must be 8, 16, 24 or 32"); this.data = null; } }
public static List <BigInteger> getPrimes(BigInteger m) { if (max < m) { IncreaseMax(m); } while (index < m) { OutputConsole.Write($"Current index:{index}, needed:{m}"); Thread.Sleep(1000); } List <BigInteger> list = new List <BigInteger>(); lock (primeList) { list = primeList.Where(n => n <= m).ToList(); } return(list); }
private void decryptButton_Click(object sender, EventArgs e) { if (currentMode == Mode.Image && image != null) { string text; if (random.Checked || randomM2.Checked) { text = Test1.GetDecryptedTextFromImage(image); } else { text = Test1.GetDecryptedTextFromImageLinear(image); } if (text != null) { textBox.Text = text; OutputConsole.Write("Text decrypted"); } else { //MessageBox.Show("This image doesn't have an encrypted text or an error occurred"); } } if (currentMode == Mode.Audio && audio != null) { string text; if (random.Checked) { text = AudioSteganography.DecryptText(audio); } else { text = AudioSteganography.DecryptTextLinear(audio); } if (text != null) { textBox.Text = text; OutputConsole.Write("Text decrypted"); } } }
public static string DecryptTextLinear(byte[] wav) { WavAudio audio = new WavAudio(wav); string text = string.Empty; uint n = 0; uint value = 0; string pass = string.Format(audio.bitsPerSample.ToString()); AESEncrypt encrypt = new AESEncrypt(); OutputConsole.Write("Processing wav file..."); do { value = 0; for (int x = 0; x < 8; x++) { uint sample = n; uint sampleValue = audio.samples[sample]; value = value | ((sampleValue & 1) << x); n++; } if (value != 0) { text += Convert.ToChar(value); } } while (value != 0); OutputConsole.Write("Decrypting text..."); try { return(encrypt.DecryptString(text, pass)); } catch (Exception e) { OutputConsole.Write("Error: Text not found"); Console.WriteLine(e.Message); return(null); } }
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(); } } }
public static HiddenFile GetFileFromImage2(Image image) { try { Bitmap img = new Bitmap(image); int maxLinear = image.Width * image.Height; SeedRNG generator = new SeedRNG((maxLinear + image.Width).GetHashCode(), maxLinear, true); OutputConsole.Write("Seed generated"); string text = string.Empty; int value = 0; //Read file length OutputConsole.Write("Processing image..."); OutputConsole.Write("Reading metadata..."); do { Point point = LinearIndexToPoint(generator.NextN, image.Width, image.Height); Color pixel = img.GetPixel(point.X, point.Y); value = DecodePixel(pixel); if (value != '#') { text += Convert.ToChar(value); } } while (value != '#' && char.IsNumber((char)value)); int filelength = int.Parse(text); OutputConsole.Write(string.Format("Extracted file size: {0} bytes", filelength)); text = string.Empty; value = 0; //Read filename do { Point point = LinearIndexToPoint(generator.NextN, image.Width, image.Height); Color pixel = img.GetPixel(point.X, point.Y); value = DecodePixel(pixel); if (value != 0) { text += Convert.ToChar(value); } } while (value != 0); string filename = text; OutputConsole.Write(string.Format("Extracted file name: {0}", filename)); byte[] file = new byte[filelength]; for (int i = 0; i < filelength; i++) { Point point = LinearIndexToPoint(generator.NextN, image.Width, image.Height); Color pixel = img.GetPixel(point.X, point.Y); value = DecodePixel(pixel); file[i] = (byte)value; } OutputConsole.Write(string.Format("Extracted file content")); HiddenFile f = new HiddenFile(file, filename); f.cipherFile((maxLinear + img.Width).GetHashCode()); OutputConsole.Write("Ciphering file..."); return(f); } catch (Exception e) { OutputConsole.Write("Error: File not found"); Console.WriteLine(e.Message); return(null); } }
public static byte[] EncryptFile2(byte[] wav, byte[] file, string filename) { WavAudio audio = new WavAudio(wav); uint value = 0; int extraBytes = 2 + filename.Length + file.Length.ToString().Length; HiddenFile f = new HiddenFile(file, filename); OutputConsole.Write(string.Format("File size: {0} bytes", file.Length)); f.cipherFile((int)audio.totalSamples); if (file.Length <= Math.Floor((double)(audio.totalSamples / 8)) - extraBytes) { SeedURNG generator = new SeedURNG(audio.totalSamples, audio.totalSamples, true); OutputConsole.Write("Seed generated"); OutputConsole.Write("Ciphering file"); OutputConsole.Write("Processing wav file..."); OutputConsole.Write("Writing metadata..."); //Write file size for (int i = 0; i < file.Length.ToString().Length; i++) { value = file.Length.ToString()[i]; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; } } value = '#'; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; } //Write file name for (int i = 0; i < filename.Length; i++) { value = filename[i]; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; } } value = 0; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; } //Write file content OutputConsole.Write("Writing file data..."); for (int i = 0; i < file.Length; i++) { value = f.file[i]; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; sampleValue = (sampleValue & 0xFFFFFFFE) | ((value >> x) & 1); audio.samples[sample] = sampleValue; } } } else { OutputConsole.Write("Error"); return(null); } OutputConsole.Write("Finished embedding file"); OutputConsole.Write(string.Format("Used {0} samples", (file.Length + extraBytes) * 8)); audio.Save(); return(audio.data); }
public static HiddenFile DecryptFile2(byte[] wav) { try { WavAudio audio = new WavAudio(wav); string text = string.Empty; SeedURNG generator = new SeedURNG(audio.totalSamples, audio.totalSamples, true); OutputConsole.Write("Seed generated"); OutputConsole.Write("Processing wav file..."); OutputConsole.Write("Reading metadata..."); uint value = 0; do { value = 0; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; value = value | ((sampleValue & 1) << x); } if (value != '#') { text += Convert.ToChar(value); } } while (value != '#' && char.IsNumber((char)value)); int filesize = int.Parse(text); OutputConsole.Write(string.Format("Extracted file size: {0} bytes", filesize)); text = string.Empty; do { value = 0; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; value = value | ((sampleValue & 1) << x); } if (value != 0) { text += Convert.ToChar(value); } } while (value != 0); string filename = text; OutputConsole.Write(string.Format("Extracted file name: {0}", filename)); byte[] file = new byte[filesize]; for (int i = 0; i < filesize; i++) { value = 0; for (int x = 0; x < 8; x++) { uint sample = generator.NextN; uint sampleValue = audio.samples[sample]; value = value | ((sampleValue & 1) << x); } file[i] = (byte)value; } OutputConsole.Write(string.Format("Extracted file content")); HiddenFile f = new HiddenFile(file, filename); OutputConsole.Write("Ciphering file..."); f.cipherFile((int)audio.totalSamples); return(f); } catch (Exception e) { return(null); } }
private static void EncodeFileWithColor2(ref Bitmap img, byte[] file, string filename) { Bitmap backup = img.Clone() as Bitmap; int maxLinear = img.Width * img.Height; OutputConsole.Write(string.Format("File size: {0}", FileSizeFormatProvider.GetFileSize(file.Length))); SeedRNG generator = new SeedRNG((maxLinear + img.Width).GetHashCode(), maxLinear, true); OutputConsole.Write("Seed generated"); int extraBytes = 2 + filename.Length + file.Length.ToString().Length; HiddenFile f = new HiddenFile(file, filename); f.cipherFile((maxLinear + img.Width).GetHashCode()); OutputConsole.Write("Ciphering file..."); if (file.Length < maxLinear - extraBytes) { string fileLength = file.Length.ToString(); OutputConsole.Write("Processing image..."); OutputConsole.Write("Writing metadata..."); for (int i = 0; i < fileLength.Length; i++) { Point point = LinearIndexToPoint(generator.NextN, img.Width, img.Height); Color pixel = img.GetPixel(point.X, point.Y); char letter = fileLength[i]; int value = Convert.ToInt32(letter); img.SetPixel(point.X, point.Y, EncodePixel(pixel, value)); } //Insert # to separate file length from filename Point point1 = LinearIndexToPoint(generator.NextN, img.Width, img.Height); Color pixel1 = img.GetPixel(point1.X, point1.Y); int value1 = Convert.ToInt32('#'); img.SetPixel(point1.X, point1.Y, EncodePixel(pixel1, value1)); //Insert filename and finish with null char for (int i = 0; i < filename.Length; i++) { Point point = LinearIndexToPoint(generator.NextN, img.Width, img.Height); Color pixel = img.GetPixel(point.X, point.Y); char letter = filename[i]; int value = Convert.ToInt32(letter); img.SetPixel(point.X, point.Y, EncodePixel(pixel, value)); } point1 = LinearIndexToPoint(generator.NextN, img.Width, img.Height); pixel1 = img.GetPixel(point1.X, point1.Y); value1 = 0; img.SetPixel(point1.X, point1.Y, EncodePixel(pixel1, value1)); OutputConsole.Write("Writing file data..."); //Write file for (int i = 0; i < file.Length; i++) { Point point = LinearIndexToPoint(generator.NextN, img.Width, img.Height); Color pixel = img.GetPixel(point.X, point.Y); int value = f.file[i]; img.SetPixel(point.X, point.Y, EncodePixel(pixel, value)); } OutputConsole.Write("Finished embedding file"); } else { OutputConsole.Write("File size is greater than total pixels in image with extra data, resize or use another image to encrypt this file"); img = null; } }
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(); } }