public void HSTest() { string filename1 = "C:\\Users\\mokry\\Desktop\\Uroboros_Files\\Grayscale_images\\cleaned.png"; Bitmap inputImage = new Bitmap(filename1); string message = "myMessage"; HSHeader header = new HSHeader(MessageType.Plaintext, message.Length); InputMessage inputMessageWithHeader = new InputMessage(message, header); Bitmap outputImage = HS.Instance.Encode(inputImage, inputMessageWithHeader); Dictionary <int, int> histogram = HS.Instance.calculateHistogram(inputImage); Tuple <int, int, int, int> myTuple = HS.Instance.findMinAndMax(histogram); int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; double error = MSE.Instance.CalculateDifference(inputImage, outputImage); Assert.AreNotEqual(0, error); Console.WriteLine("Error is {0}", error); outputImage = HS.Instance.Clean(outputImage, minIndex, maxIndex); error = MSE.Instance.CalculateDifference(inputImage, outputImage); Assert.AreEqual(0, error); }
public void ShouldCalculateDifferencesOnHS(int payloadSize, string filename) { payloadSize = payloadSize / 8; var message = GeneratePayload(payloadSize); Bitmap cleanImage = new Bitmap(filename); HSHeader header = new HSHeader(MessageType.Plaintext, message.Length); string inputMeesageInBits = MessageConverter.Instance.TextToBit(message); IInputMessage inputMessage = new InputMessage(inputMeesageInBits, header); Console.WriteLine("Message size is in bits is {0}", inputMeesageInBits.Length); Console.WriteLine("Message with header size is {0}", inputMeesageInBits.Length + HSHeaderConstants.PlainTextHeaderLength); Dictionary <int, int> histogram = HS.Instance.calculateHistogram(cleanImage); Tuple <int, int, int, int> myTuple = HS.Instance.findMinAndMax(histogram); int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; int maxIndexValue = myTuple.Item2; var capacity = maxIndexValue; Console.WriteLine("Image capacity is {0}", capacity); Bitmap encryptedImage = HS.Instance.Encode(cleanImage, inputMessage); OutputMessage imageMessageInBits = HS.Instance.Decode(encryptedImage, minIndex, maxIndex); string imageMessage = AlgorithmUtility.bitMessageToText(imageMessageInBits.GetContent(), (int)HSHeaderConstants.PlainTextHeaderLength); Assert.AreEqual(message, imageMessage); double mse = MSE.Instance.CalculateDifference(cleanImage, encryptedImage); Console.WriteLine("MSE is {0}", mse); double psnr = PSNR.Instance.CalculateDifference(mse); Console.WriteLine("PSNR is {0}", psnr); double imageSimilarity; ImageDifference.Instance.CalculateDifference(cleanImage, encryptedImage, out imageSimilarity); Console.WriteLine("Image Similiarity is {0}", imageSimilarity); Bitmap cleanedImage = HS.Instance.Clean(encryptedImage, minIndex, maxIndex); var error = MSE.Instance.CalculateDifference(cleanedImage, cleanImage); Assert.AreEqual(0, error); }
public void ShouldReadEncryptedTextInputMessageLeft(string message) { Bitmap cleanImage = new Bitmap(cleanImagePathLeft); HSHeader header = new HSHeader(MessageType.Plaintext, message.Length, 0); string inputMeesageInBits = MessageConverter.Instance.TextToBit(message); IInputMessage inputMessage = new InputMessage(inputMeesageInBits, header); Bitmap encryptedImage = HS.Instance.Encode(cleanImage, inputMessage); Dictionary <int, int> histogram = HS.Instance.calculateHistogram(cleanImage); Tuple <int, int, int, int> myTuple = HS.Instance.findMinAndMax(histogram); int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; OutputMessage imageMessageInBits = HS.Instance.Decode(encryptedImage, minIndex, maxIndex); string imageMessage = AlgorithmUtility.bitMessageToText(imageMessageInBits.GetContent(), (int)HSHeaderConstants.PlainTextHeaderLength); Assert.AreEqual(message, imageMessage); }
public void ShouldReadEncryptedBinaryInputMessageRight() { Bitmap binaryImage = new Bitmap(binaryImagePath); Bitmap cleanImage = new Bitmap(cleanImagePathRight); string loadedImageContent = MessageConverter.Instance.BinaryImageToBit(binaryImage, binaryImage.Width, binaryImage.Height); HSHeader header = new HSHeader(MessageType.BinaryImage, loadedImageContent.Length, binaryImage.Width, binaryImage.Height); IInputMessage inputMessageWithHeader = new InputMessage(loadedImageContent, header); Bitmap encryptedImage = HS.Instance.Encode(cleanImage, inputMessageWithHeader); Dictionary <int, int> histogram = HS.Instance.calculateHistogram(cleanImage); Tuple <int, int, int, int> myTuple = HS.Instance.findMinAndMax(histogram); int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; OutputMessage outputMessage = HS.Instance.Decode(encryptedImage, minIndex, maxIndex); string withoutHeader = outputMessage.GetContent().Substring((int)HSHeaderConstants.BinaryImageHeaderLength); Assert.AreEqual(loadedImageContent, withoutHeader); Bitmap drawnImage = ImageDrawer.Instance.DrawBinaryImage(withoutHeader, outputMessage.GetHeaderData().GetImageWidth(), outputMessage.GetHeaderData().GetImageHeight()); drawnImage.Save(savePath + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss") + ".png"); }
public void ShouldCleanEncryptedImage(string inputMessage, string cleanImagePath) { Bitmap inputImage = new Bitmap(cleanImagePath); HSHeader header = new HSHeader(MessageType.Plaintext, inputMessage.Length); IInputMessage inputMessageWithHeader = new InputMessage(inputMessage, header); Bitmap outputImage = HS.Instance.Encode(inputImage, inputMessageWithHeader); Dictionary <int, int> histogram = HS.Instance.calculateHistogram(inputImage); Tuple <int, int, int, int> myTuple = HS.Instance.findMinAndMax(histogram); int minIndex = myTuple.Item3; int maxIndex = myTuple.Item4; double error = MSE.Instance.CalculateDifference(inputImage, outputImage); Assert.AreNotEqual(0, error); Console.WriteLine("Error is {0}", error); outputImage = HS.Instance.Clean(outputImage, minIndex, maxIndex); error = MSE.Instance.CalculateDifference(inputImage, outputImage); Assert.AreEqual(0, error); }
// placeholder function private void encrypt_Click(object sender, RoutedEventArgs e) { // TO DO add checks for nulls // if message is image string message = null; MessageType messageType = MessageType.Plaintext; Bitmap imageToEncode = null; if (Equals(messageTabControl.SelectedItem, textItem)) { TextViewer tab = messageTabControl.SelectedContent as TextViewer; message = tab.textBox.Text; } else if (Equals(messageTabControl.SelectedItem, binaryImageItem)) { ImageViewer tab = messageTabControl.SelectedContent as ImageViewer; imageToEncode = new Bitmap(tab.filename); messageType = MessageType.BinaryImage; message = MessageConverter.Instance.BinaryImageToBit(imageToEncode, imageToEncode.Width, imageToEncode.Height); } else if (Equals(messageTabControl.SelectedItem, grayscaleImageItem)) { ImageViewer tab = messageTabControl.SelectedContent as ImageViewer; imageToEncode = new Bitmap(tab.filename); messageType = MessageType.GrayscaleImage; message = MessageConverter.Instance.GrayscaleImageToBit(imageToEncode, imageToEncode.Width, imageToEncode.Height); } else if (Equals(messageTabControl.SelectedItem, colorImageItem)) { ImageViewer tab = messageTabControl.SelectedContent as ImageViewer; imageToEncode = new Bitmap(tab.filename); messageType = MessageType.ColorImage; message = MessageConverter.Instance.ColorImageToBit(imageToEncode, imageToEncode.Width, imageToEncode.Height); } Bitmap image = new Bitmap(carrierViewer.filename); if (algorithmsComboBox.SelectedItem.ToString() == "LSB") { if (message != null) { LSBHeader header = null; switch (messageType) { case MessageType.Plaintext: header = new LSBHeader(MessageType.Plaintext, message.Length); message = MessageConverter.Instance.TextToBit(message); break; case MessageType.BinaryImage: header = new LSBHeader(MessageType.BinaryImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; case MessageType.GrayscaleImage: header = new LSBHeader(MessageType.GrayscaleImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; case MessageType.ColorImage: header = new LSBHeader(MessageType.ColorImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; } InputMessage inputMessageWithHeader = new InputMessage(message, header); image = LSB.Instance.Encode(image, inputMessageWithHeader); } } else if (algorithmsComboBox.SelectedItem.ToString() == "Histogram shifting") { HSHeader header = null; if (message != null) { switch (messageType) { case MessageType.Plaintext: header = new HSHeader(MessageType.Plaintext, message.Length); message = MessageConverter.Instance.TextToBit(message); break; case MessageType.BinaryImage: header = new HSHeader(MessageType.BinaryImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; case MessageType.GrayscaleImage: header = new HSHeader(MessageType.GrayscaleImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; case MessageType.ColorImage: header = new HSHeader(MessageType.ColorImage, message.Length, imageToEncode.Width, imageToEncode.Height); break; } } InputMessage inputMessageWithHeader = new InputMessage(message, header); image = HS.Instance.Encode(image, inputMessageWithHeader); } ImageFormat format = ImageFormat.Png; SaveFileDialog sfd = new SaveFileDialog(); string ext = System.IO.Path.GetExtension(carrierViewer.filename); switch (ext) { case ".png": sfd.Filter = "Save Format|*.png"; format = ImageFormat.Png; break; case ".jpg": sfd.Filter = "Save Format|*.jpg"; format = ImageFormat.Jpeg; break; case ".bmp": sfd.Filter = "Save Format|*.bmp"; format = ImageFormat.Bmp; break; } if (sfd.ShowDialog() == true) { image.Save(sfd.FileName); } //Bitmap encryptedImage = new Bitmap(sfd.FileName); }