问题描述
我在每个像素的lsb中编码了一条消息。我该如何找回它?当我读取每个像素的LSB时,确实将每个位输入字节数组或将零/一个输入到字符数组中?不确定要调用什么编码功能呢?我应该使用foreach循环和Encoding.UTF8.GetString(Message)但是char数组中的所有1和0都变为单个字符串?
我刚刚修改过我的代码。我拉出的信息形成了我放入
stringbuilder对象的图像,由1和0组成。索引for循环后,我可以看到我尝试了各种方法,但返回相同的值,任何建议
I have encoded a message in the lsb of each pixel. How would i retrieve it? When i read the LSB of each pixel do input each bit into a byte array or a zero/one into a char array? Unsure what encoding function to call then? I should use a foreach loop and Encoding.UTF8.GetString(Message)but all the ones and zeros from the char array into a single string?
I have just modified my code. The message i pull form the image i put into a
stringbuilder object consist of ones and zeros. After the indexed for loops, one can see i have tried various methods but the same value is returned, any suggestions
private void button2_Click(object sender, EventArgs e)
{
int c = sb.Length,x,y,z=0;
char[] Message= new char[c];
StringBuilder RetreivedMessage = new StringBuilder();
for (x = 0, y = 0; x < image1.Width && z < c; x++)
{
for (y = 0; y < image1.Height && z < c; y++)
{
Color pixelColor = image1.GetPixel(x, y);
string binary1 = Convert.ToString(pixelColor.R, 2);
//byte NewRed, NewGreen, NewBlue;
if (binary1[binary1.Length -1] == '0')
{
RetreivedMessage.Append('0');
z++;
if (z == c)
{
break;
}
}
else
{
RetreivedMessage.Append('1');
z++;
if (z == c)
{
break;
}
}
binary1 = Convert.ToString(pixelColor.G, 2);
//byte NewRed, NewGreen, NewBlue;
if (binary1[binary1.Length - 1] == '0')
{
RetreivedMessage.Append('0');
z++;
if (z == c)
{
break;
}
}
else
{
RetreivedMessage.Append('1');
z++;
if (z == c)
{
break;
}
}
binary1 = Convert.ToString(pixelColor.B, 2);
//byte NewRed, NewGreen, NewBlue;
if (binary1[binary1.Length - 1] == '0')
{
RetreivedMessage.Append('0');
z++;
if (z == c)
{
break;
}
}
else
{
RetreivedMessage.Append('1');
z++;
if (z == c)
{
break;
}
}
//string binary1 = Convert.ToString(pixelColor.R, 2);
//char last1 = binary1[binary1.Length - 1];
}
}
string FinalRetreivedMessage = RetreivedMessage.ToString();
//Byte[] buf = Encoding.Unicode.GetBytes(RetreivedMessage.ToString());
Byte[] buf = Encoding.Unicode.GetBytes(RetreivedMessage.ToString());
string result = System.Text.Encoding.Unicode.GetString(buf);
//String result = Encoding.Unicode.GetString(buf);
StringBuilder r2 = new StringBuilder();
//foreach (Byte b in Encoding.Unicode.GetBytes(FinalRetreivedMessage))
// {
// r2.Append(Convert.ToString());
//}
}
推荐答案
string FinalRetreivedMessage = RetreivedMessage.ToString();
int count = FinalRetreivedMessage.Length / 8;
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
UTF8Encoding enc = new UTF8Encoding();
var StringBytes = new byte[count];
for (int i = 0; i < count; i++)
StringBytes[i] = Convert.ToByte(FinalRetreivedMessage.Substring(i * 8, 8), 2);
//StringBytes[i] = encoding.GetBytes(FinalRetreivedMessage.Substring(i * 8, 8), 2);
string FinalResult = enc.GetString(StringBytes);
string FinalRetreivedMessage = RetreivedMessage.ToString();
int count = FinalRetreivedMessage.Length / 8;
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
UTF8Encoding enc = new UTF8Encoding();
var StringBytes = new byte[count];
for (int i = 0; i < count; i++)
StringBytes[i] = Convert.ToByte(FinalRetreivedMessage.Substring(i * 8, 8), 2);
//StringBytes[i] = encoding.GetBytes(FinalRetreivedMessage.Substring(i * 8, 8), 2);
string FinalResult = enc.GetString(StringBytes);
这篇关于LSB算法,隐写术项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!