隐身图像 [英] steganograpy in image
问题描述
public class Bit
{
public static void Replace(ref byte b, int pos, byte value)
{
b = (byte) (value == 1 ? b | (1 << pos) : b & ~(1 << pos));
}
public static byte Extract(byte b, int pos)
{
return (byte) ((b & (1 << pos)) >> pos);
}
}
public static void Encode(Stream inStream, byte[] message, Stream outStream)
{
int byteRead;
byte byteWrite;
int i = 0;
int j = 0;
byte bit;
while((byteRead = inStream.ReadByte()) != -1)
{
byteWrite = (byte) byteRead;
if (i<message.Length)
{
// Extract the bit at the j position
bit = Bit.Extract(message[i], j++);
// Replace the LSB of byteWrite with "bit"
Bit.Replace(ref byteWrite, 0, bit);
// Every 8 bits process another byte of "message"
if (j==8) {j=0; i++;}
}
outStream.WriteByte(byteWrite);
}
if (i<message.Length)
throw new Exception("The cover is too small to contain the message to hide");
}
此类用于为每个像素隐藏最低有效位中的数据
通过将RGB移位一位.
#如何为每个像素移动四个最低有效位来隐藏数据
#如何通过过滤RGB并使用一种颜色将数据隐藏在蓝色的最低有效位中来隐藏数据
This classes use to hiding data in the Least Significant Bit for each pixel
by shifting one bit from RGB.
# how can hiding data by shifting four Least Significant Bit for each pixel
# how can hiding data by filtering RGB and use one color to hiding data in the Least Significant Bit of blue color
推荐答案
并将其最近上传到Google Code,以防其他人从中受益.它支持将文件编码为每个像素的RGB部分可变数量的位数,加密(包括标题和原始文件名)以及自动调整图像大小,以便图像始终是最佳尺寸.
2Pix主项目页面(包含示例和说明) [使用指针将数据编码为图像的代码(快速). [ ^ ]
代表加密文件的代码(具有合理的可否认性) [
I wrote something to do this a while ago, and recently uploaded it to Google Code in case anyone else could benefit from it. It supports encoding files into a variable number of bits per RGB part of a pixel, encryption (including the header and original file name), and automatic image resizing so that the image is always the best size.
The 2Pix main project page (with examples and descriptions)[^]
Direct links to code:
The code that encodes data into an image using pointers (fast).[^]
The code that represents an encrypted file (with plausible deniability)[^]
此类用于隐藏数据每个像素的最低有效位
通过从RGB移位一位.
This classes use to hiding data in the Least Significant Bit for each pixel
by shifting one bit from RGB.
实际上,发布的代码替换了原始流的每个字节的每个最低有效位.例如,如果流包含24位图像,则它将替换每个RGB分量的最低有效位.
(1)因此,替换每个RGB组件的一半并不是一个好主意(您可能会注意到该伪像,这没有实现隐藏的目的)
(2)如果您知道图像格式,则可以轻松地有选择地更改RGB分量之一:对于24位图像,每3个读取字节只需要更改其中的一个,直接将其他字节复制到输出流即可.
Actually the code posted replaces each least significant bit of each byte of the original stream. If, for instance, the stream contains a 24 bit image then it replaces the least significant bit of each RGB component.
(1) Hence replacing half of each RGB component doesn''t look a good idea (you''ll probably notice the artifact, failing the very purpose of hiding)
(2) You may easily selectively change one of the RGB component if you know the image format: e.g. for a 24 bit image, every 3 read bytes you just need to change one of them, directly copying the others to the output stream.
我对隐写术一无所知,但是有关它的问题有时会出现.通常,发问者最终会被 Corinna John [
I don''t really know anything about Steganography, but questions about it appear every once and a while. Usually the questioners end up being pointed to articles on Code Project by Corinna John[^]. It might not have exactly the answer you are looking for, but I hope it helps you.
这篇关于隐身图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!