Click here to Skip to main content
15,885,012 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
whatever code I have write for Steganography with that code Encryption has done but when I try for Decryption then it gives me empty message of decrypted value please help

What I have tried:

C#
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 originalText="My message to encrypr"; 
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
}


reference:
http://www.c-sharpcorner.com/UploadFile/6f0898/simple-steganography-encryption-and-decryption-huge-message/
Posted
Updated 22-Jul-16 13:39pm
v2

There is a whole article series on steganography, using C#, here at Code Project: http://www.codeproject.com/Articles/Corinna-John#Article[^].
 
Share this answer
 
v2
Comments
Atmesh Sonawane 22-Jul-16 3:01am    
Thanks...but where is Image Steganography there...I have to encode my message into image and decrypt the same message from encrypted image..Please help
CPallini 22-Jul-16 3:07am    
You are welcome.
You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

With the debugger, you will exactly what your code is doing.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900