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
- string strFullText = "";
- Bitmap bmImage = new Bitmap(txtFileName.Text);
-
- Color pix = bmImage.GetPixel(bmImage.Width - 1, bmImage.Height - 1);
- bmImage.SetPixel(bmImage.Width - 1, bmImage.Height - 1, Color.FromArgb(pix.R, pix.G, txtEncMessage.TextLength));
-
- for (int iWidth = 0; iWidth < bmImage.Width; iWidth++)
- {
- for (int iLength = 0; iLength < bmImage.Height; iLength++)
- {
- pix = bmImage.GetPixel(iWidth, iLength);
- if (iWidth < 1 && iLength < txtEncMessage.TextLength)
- {
- char chMessageLetter = Convert.ToChar(txtEncMessage.Text.Substring(iLength, 1));
- int intMessageLetterValue = Convert.ToInt32(chMessageLetter);
- bmImage.SetPixel(iWidth, iLength, Color.FromArgb(pix.R, pix.G, intMessageLetterValue));
- pix = bmImage.GetPixel(iWidth, iLength);
- }
-
- }
- }
- SaveFileDialog savFD = new SaveFileDialog();
- savFD.Filter = "Image Files (*.png, *.jpg ) | *.png; *.jpg";
- if (savFD.ShowDialog() == DialogResult.OK)
- {
- txtFileName.Text = savFD.FileName.ToString();
- pbImage.ImageLocation = txtFileName.Text;
- bmImage.Save(txtFileName.Text);
- }
Code Block for Decoding
- string strFullText = "";
- int iLengthOfTheText = 0;
- OpenFileDialog opnFD = new OpenFileDialog();
- opnFD.Filter = "Image Files (*.png, *.jpg ) | *.png; *.jpg";
- if (opnFD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- txtFileName.Text = opnFD.FileName.ToString();
- pbImage.ImageLocation = txtFileName.Text;
- }
- Bitmap bmImage = new Bitmap(txtFileName.Text);
-
- Color pix = bmImage.GetPixel(bmImage.Width - 1, bmImage.Height - 1);
- iLengthOfTheText = pix.B;
- for (int iWidth = 0; iWidth < bmImage.Width; iWidth++)
- {
- for (int iLength = 0; iLength < bmImage.Height; iLength++)
- {
- pix = bmImage.GetPixel(iWidth, iLength);
- if (iWidth < 1 && iLength < iLengthOfTheText)
- {
- int intMessageLetterValue = pix.B;
- char chMessageLetter = Convert.ToChar(intMessageLetterValue);
- string strChar = System.Text.Encoding.ASCII.GetString(new byte[]
- {
- Convert.ToByte(chMessageLetter)
- });
- strFullText = strFullText + strChar;
- }
- }
- }
- txtDecMessage.Text = strFullText;
- }