Hiding information using Pixels

Introduction

The concept of message hiding is not new, it has been around for centuries. The word Steganography literally means ”covered writing”. Steganography’s primary goal is to hide data within some other data such that the hidden data cannot be detected even if it is being sought. This way of transmitting information has been used for secret communication. Steganography is widely used by Information/coding theory, Digital Signals, Data Networking, Visual Systems, Data Compression, etc. There are many ways of Steganoing the message in the image/Audio/Video files. In this article I’ve presented simple way of hiding message using pixels.

Code Execution

I've implemented two main methods for that purpose to encode and decode the hidden messages: Encode and Decode. Please use the attached source code for further explanation.

Blocks of code should be set as style "Formatted" like the following:

Code Block for Encoding

  1. string strFullText = "";  
  2. Bitmap bmImage = new Bitmap(txtFileName.Text);  
  3. // Setting the Length of the Text in the same image   
  4. Color pix = bmImage.GetPixel(bmImage.Width - 1, bmImage.Height - 1);  
  5. bmImage.SetPixel(bmImage.Width - 1, bmImage.Height - 1, Color.FromArgb(pix.R, pix.G, txtEncMessage.TextLength));  
  6. // End of Length Setting process  
  7. for (int iWidth = 0; iWidth < bmImage.Width; iWidth++)   
  8. {  
  9.     for (int iLength = 0; iLength < bmImage.Height; iLength++)   
  10.     {  
  11.         pix = bmImage.GetPixel(iWidth, iLength);  
  12.         if (iWidth < 1 && iLength < txtEncMessage.TextLength)   
  13.         {  
  14.             char chMessageLetter = Convert.ToChar(txtEncMessage.Text.Substring(iLength, 1));  
  15.             int intMessageLetterValue = Convert.ToInt32(chMessageLetter);  
  16.             bmImage.SetPixel(iWidth, iLength, Color.FromArgb(pix.R, pix.G, intMessageLetterValue));  
  17.             pix = bmImage.GetPixel(iWidth, iLength);  
  18.         }  
  19.   
  20.     }  
  21. }  
  22. SaveFileDialog savFD = new SaveFileDialog();  
  23. savFD.Filter = "Image Files (*.png, *.jpg ) | *.png; *.jpg";  
  24. if (savFD.ShowDialog() == DialogResult.OK)   
  25. {  
  26.     txtFileName.Text = savFD.FileName.ToString();  
  27.     pbImage.ImageLocation = txtFileName.Text;  
  28.     bmImage.Save(txtFileName.Text);  
  29. }
Code Block for Decoding
  1. string strFullText = "";  
  2. int iLengthOfTheText = 0;  
  3. OpenFileDialog opnFD = new OpenFileDialog();  
  4. opnFD.Filter = "Image Files (*.png, *.jpg ) | *.png; *.jpg";  
  5. if (opnFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)   
  6. {  
  7.     txtFileName.Text = opnFD.FileName.ToString();  
  8.     pbImage.ImageLocation = txtFileName.Text;  
  9. }  
  10. Bitmap bmImage = new Bitmap(txtFileName.Text);  
  11. // Getting the length of the Hidden text  
  12. Color pix = bmImage.GetPixel(bmImage.Width - 1, bmImage.Height - 1);  
  13. iLengthOfTheText = pix.B;  
  14. for (int iWidth = 0; iWidth < bmImage.Width; iWidth++)   
  15. {  
  16.     for (int iLength = 0; iLength < bmImage.Height; iLength++)   
  17.     {  
  18.         pix = bmImage.GetPixel(iWidth, iLength);  
  19.         if (iWidth < 1 && iLength < iLengthOfTheText)   
  20.         {  
  21.             int intMessageLetterValue = pix.B;  
  22.             char chMessageLetter = Convert.ToChar(intMessageLetterValue);  
  23.             string strChar = System.Text.Encoding.ASCII.GetString(new byte[]   
  24.             {  
  25.                 Convert.ToByte(chMessageLetter)  
  26.             });  
  27.             strFullText = strFullText + strChar;  
  28.         }  
  29.     }  
  30. }  
  31. txtDecMessage.Text = strFullText;  
  32. }