Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I`m trying to do some c# programming for steganography. i tried to decode but the get ????? instead of the message hidden .

this is Encoding code.


C#
Bitmap img = new Bitmap(textBoxFilePath.Text);

            for (int i = 0; i < img.Width; i++)
            {
                for (int j = 0; j < img.Height; j++)
                {
                    Color pixel = img.GetPixel(i, j);

                    if (i < 1 && j < textBoxMessage.TextLength)
                    {
                        Console.WriteLine("R = [" + i + "][" + j + "] = " + pixel.R);
                        Console.WriteLine("G = [" + i + "][" + j + "] = " + pixel.G);
                        Console.WriteLine("G = [" + i + "][" + j + "] = " + pixel.B);

                        char letter = Convert.ToChar(textBoxMessage.Text.Substring(j, 1));
                        int value = Convert.ToInt32(letter);
                        Console.WriteLine("letter : " + letter + " value : " + value);

                        img.SetPixel(i, j, Color.FromArgb(pixel.R, pixel.G, value));
                    }

                    if (i == img.Width - 1 && j == img.Height - 1)
                    {
                        img.SetPixel(i, j, Color.FromArgb(pixel.R, pixel.G, textBoxMessage.TextLength));
                    }

                }
            }

            SaveFileDialog saveFile = new SaveFileDialog();
            saveFile.Filter = "Image Files (*.png, *.jpg) | *.png; *.jpg";
            saveFile.InitialDirectory = @"C:\Users\metech\Desktop";

            if (saveFile.ShowDialog() == DialogResult.OK)
            {
                textBoxFilePath.Text = saveFile.FileName.ToString();
                pictureBox1.ImageLocation = textBoxFilePath.Text;

                img.Save(textBoxFilePath.Text);
            }
        }


What I have tried:

Decoding code.


C#
private void buttonDecode_Click(object sender, EventArgs e)
{
    Bitmap img = new Bitmap(textBoxFilePath.Text);
    string message = "";

    Color lastpixel = img.GetPixel(img.Width - 1, img.Height - 1);
    int msgLength = lastpixel.B;

    for (int i = 0; i < img.Width; i++)
    {
        for (int j = 0; j < img.Height; j++)
        {
            Color pixel = img.GetPixel(i, j);

            if (i < 1 && j < msgLength)
            {
                int value = pixel.B;
                char c = Convert.ToChar(value);
                string letter = System.Text.Encoding.ASCII.GetString(new byte[] { Convert.ToByte(c) });

                message = message + letter;
            }
        }
    }

    textBoxMessage.Text = message;
}
Posted
Updated 13-Nov-16 16:16pm
v6
Comments
Tomas Takac 11-Nov-16 2:47am    
Do you care to explain how the information is encoded? Seems like the blue component is the unicode value of the character. But I don't get the extra step with ASCII encoding - what is it good for?
Member 12844786 13-Nov-16 9:47am    
i tried to use lsb method.
Karthik_Mahalingam 11-Nov-16 5:49am    
use debugger

1 solution

Quote:
I`m trying to do some c# programming for steganography. i tried to decode but the get ????? instead of the message hidden .
You build the message from channel b where channel b is the message. I have never saw steganography that take a full channel. Please explain your encoding method. With the debugger, you will see exactly what is doing your code. I guess you should show the encoding code to help us to understand what you do.

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[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
When the code don't do what is expected, you are close to a bug.

[UpDate]
Never ever use JPEG image format with steganography. Steganography imply lossless compression and JPEG is using a lossy compression.
 
Share this answer
 
v2
Comments
Member 12844786 13-Nov-16 9:48am    
this is the encoding part.
i will try using the dubugger. thanks for the information.

Bitmap img = new Bitmap(textBoxFilePath.Text);

for (int i = 0; i < img.Width; i++)
{
for (int j = 0; j < img.Height; j++)
{
Color pixel = img.GetPixel(i, j);

if (i < 1 && j < textBoxMessage.TextLength)
{
Console.WriteLine("R = [" + i + "][" + j + "] = " + pixel.R);
Console.WriteLine("G = [" + i + "][" + j + "] = " + pixel.G);
Console.WriteLine("G = [" + i + "][" + j + "] = " + pixel.B);

char letter = Convert.ToChar(textBoxMessage.Text.Substring(j, 1));
int value = Convert.ToInt32(letter);
Console.WriteLine("letter : " + letter + " value : " + value);

img.SetPixel(i, j, Color.FromArgb(pixel.R, pixel.G, value));
}

if (i == img.Width - 1 && j == img.Height - 1)
{
img.SetPixel(i, j, Color.FromArgb(pixel.R, pixel.G, textBoxMessage.TextLength));
}

}
}

SaveFileDialog saveFile = new SaveFileDialog();
saveFile.Filter = "Image Files (*.png, *.jpg) | *.png; *.jpg";
saveFile.InitialDirectory = @"C:\Users\metech\Desktop";

if (saveFile.ShowDialog() == DialogResult.OK)
{
textBoxFilePath.Text = saveFile.FileName.ToString();
pictureBox1.ImageLocation = textBoxFilePath.Text;

img.Save(textBoxFilePath.Text);
}
}
Patrice T 13-Nov-16 12:08pm    
Use Improve question to update your question.
So that everyone can pay attention to this information.

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