Introduction
As we know, Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message. Here we hide the huge message within an image.
Efficiency of the approach
We can hide nearly 2500 characters inside an image of 100 X 100 pixels. So this is a very effective way to send a huge secret message. We can also use any language, like Tamil, Sanskrit, and so on.
Concept behind the approach
Normally an image contains pixels that are an ARGB value. Here the hero of the concept is the value A. A value is responsible for the transparency of the pixel. And the range of the value is 0 to 255. And the digits of the ASCII value of any language is 2 to 4. The concept is, we store the ASCII value of each digit of a pixel one by one. In other words, by reducing the digit value (probably 0 to 9) with the A value (255 default values). And decryption is done by reversing this procedure.
C# code
The following is sample C# code for this approach.
public void encryption()
{
var originalbmp = new Bitmap(Bitmap.FromFile("../../OriginalImage.png")); //Actual image used to encrypt the message
var encryptbmp = new Bitmap(originalbmp.Width, originalbmp.Height); // To hold the encrypted image
var ascii = new List<int>(); // To store individual value of the pixels
foreach (char character in originalText)
{
int asciiValue = Convert.ToInt16(character); // Convert the character to ASCII
var firstDigit = asciiValue / 1000; // Extract the first digit of the ASCII
var secondDigit = (asciiValue - (firstDigit * 1000)) / 100; //Extract the second digit of the ASCII
var thirdDigit = (asciiValue - ((firstDigit * 1000) + (secondDigit * 100)))/10;//Extract the third digit of the ASCII
var fourthDigit = (asciiValue - ((firstDigit * 1000) + (secondDigit * 100)+(thirdDigit * 10))); //Extract the third digit of the ASCII
ascii.Add(firstDigit); // Add the first digit of the ASCII
ascii.Add(secondDigit); // Add the second digit of the ASCII
ascii.Add(thirdDigit); // Add the third digit of the ASCII
ascii.Add(fourthDigit ); // Add the fourth digit of the ASCII
}
var count = 0; // Have a count
for (int row = 0; row < originalbmp.Width; row++) // Indicates row number
{
for (int column = 0; column < originalbmp.Height; column++) // Indicate column number
{
var color = originalbmp.GetPixel(row, column); // Get the pixel from each and every row and column
encryptbmp.SetPixel(row, column, Color.FromArgb(color.A -((count < ascii .Count ) ? ascii[count]:0), color)); // Set ascii value in A of the pixel
}
}
encryptbmp.Save("../../EncryptedImage.png", ImageFormat.Png); // Save the encrypted image
}
private void decryption()
{
var characterValue = 0; // Have a variable to store the ASCII value of the character
string encryptedText = string.Empty; // Have a variable to store the encrypted text
var ascii = new List<int>(); // Have a collection to store the collection of ASCII
var encryptbmp = new Bitmap(Bitmap.FromFile("../../EncryptedImage.png")); // Load the transparent image
for (int row = 0; row < encryptbmp.Width; row++) // Indicates row number
{
for (int column = 0; column < encryptbmp.Height; column++) // Indicate column number
{
var color = encryptbmp.GetPixel(row, column); // Get the pixel from each and every row and column
ascii.Add(255 - color.A); // Get the ascii value from A value since 255 is default value
}
}
for (int i = 0; i < ascii.Count; i++)
{
characterValue = 0;
characterValue += ascii[i] * 1000; // Get the first digit of the ASCII value of the encrypted character
i++;
characterValue += ascii[i] * 100; // Get the second digit of the ASCII value of the encrypted character
i++;
characterValue += ascii[i] * 10; // Get the first third digit of the ASCII value of the encrypted character
i++;
characterValue += ascii[i]; // Get the first fourth digit of the ASCII value of the encrypted character
if (characterValue != 0)
encryptedText += char.ConvertFromUtf32(characterValue); // Convert the ASCII characterValue into character
}
MessageBox.Show(encryptedText); // Showing the encrypted message in message box
}
Image
Decrypted Message
Encrypted Image
Conclusion
Hence we can hide nearly 3333 characters inside an image of 100 X 100 pixels. So this is a very effective way to send a huge secret message. And it encrypts and decrypts with very high performance.