位提取和隐写术
我正在玩隐写术。我正在尝试从图像中提取文本文件。我能够读取文件,获取这些位,但在提取这些位时遇到问题。
int getbits( pixel p) {
return p & 0x03;
}
char extract ( pixel* image ) {
static int postion;
postion = 0;
postion = *image;
postion++;
char curChar;
curChar = '\0';
for(int i = 0; i<4; ++i) {
curChar = curChar << 2;
curChar = curChar | getbits(postion);
}
return curChar;
}
Pixel 是一个无符号字符。我有一个循环调用 extract()
和 fputc(3)
返回值。我觉得我从这些碎片中得到了垃圾。这导致我得到大量(1.5 GB)txt 文件作为回报。
void decode( PgmType* pgm, char output[80] )
{
FILE*outstream;
int i, length;
outstream = fopen(output, "w");
if(!outstream)
{
fatal("Could not open");
}
for(i=0; i < 16; ++i)
{
length = length << 2;
length = length | getbits(*pgm->image);
}
if ((length* 4) < (pgm->width * pgm->height))
{
fatal("File Too Big");
}
for (i = 0 ;i<length; ++i)
{
fputc(extract(pgm->image), outstream);
}
fclose(outstream);
}
I am playing around with steganography. I am trying to pull a text file from a image. I am able to read the file, get the bits, but I have an issue with the extraction of these bits.
int getbits( pixel p) {
return p & 0x03;
}
char extract ( pixel* image ) {
static int postion;
postion = 0;
postion = *image;
postion++;
char curChar;
curChar = '\0';
for(int i = 0; i<4; ++i) {
curChar = curChar << 2;
curChar = curChar | getbits(postion);
}
return curChar;
}
Pixel is an unsigned char. I have loop that calls extract()
and fputc(3)
the return value. I feel like I am getting garbage from these bits. Which causes me to have massive (1.5 gig) txt files in return.
void decode( PgmType* pgm, char output[80] )
{
FILE*outstream;
int i, length;
outstream = fopen(output, "w");
if(!outstream)
{
fatal("Could not open");
}
for(i=0; i < 16; ++i)
{
length = length << 2;
length = length | getbits(*pgm->image);
}
if ((length* 4) < (pgm->width * pgm->height))
{
fatal("File Too Big");
}
for (i = 0 ;i<length; ++i)
{
fputc(extract(pgm->image), outstream);
}
fclose(outstream);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您实际上只是读取图像中的第一个像素 - [编辑],因为当您尝试使用静态变量来保持计数时,正如奥利指出的那样,您会立即覆盖它。
相反,使用位置来跟踪您的计数;但将数据保存在另一个变量中:
相反,
extract()
应该类似于:You are only actually reading the first pixel in the image - [Edit] because while you are trying to use a static var to keep count, as Oli points out you're immediately overwriting it.
Instead use position to track your count; but hold the data in another var:
Instead
extract()
should look something like:Dave Rigby 的出色的诊断是正确的,但超过了
位置
作为参数(并且不在这里递增它)将导致更容易理解和更灵活的例程:然后,当您意识到更改中的所有像素时线使它非常明显,并且您宁愿使用位于斐波那契值的像素,更改很容易进行:
您可以将斐波那契计算填充到您的
extract()
中例程也是如此,但是将函数分解为最小的、最有用的部分,可以为您提供出色的易读性、出色的可测试性以及未来代码重用的最佳机会。Dave Rigby's excellent diagnosis is correct, but passing
position
as a parameter (and not incrementing it here) would lead to easier to understand and more flexible routines:Then, when you realize that changing all the pixels in a line makes it pretty obvious, and you'd rather use pixels located at Fibonacci values, the change is easy to make:
You could stuff the Fibonacci computation into your
extract()
routine too, but decomposing functions into the smallest, most useful, pieces, gives you excellent legibility, excellent testability, and best chances for future code re-use.