问题描述
我正在尝试为隐写术做一些c#编程。我试图解码但得到?????而不是隐藏的信息。
这是编码代码。
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.
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.
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;
}
推荐答案
我正在尝试为隐写术做一些c#编程。我试图解码但得到?????而不是隐藏的消息。
I`m trying to do some c# programming for steganography. i tried to decode but the get ????? instead of the message hidden .
您从通道b构建消息,其中通道b是消息。我从未见过采用完整频道的隐写术。请解释一下你的编码方法。使用调试器,您将看到您的代码到底在做什么。我想你应该显示编码代码,以帮助我们理解你的工作。
你应该学会尽快使用调试器。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。
调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。
[]
[]
调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />
当代码不做ex的时候你接近一个bug。
[UpDate]
永远不要使用带有隐写术的JPEG图像格式。隐写术意味着无损压缩,JPEG正在使用有损压缩。
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.
这篇关于这段代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!