我在玩隐写术。我正在尝试从图像中提取文本文件。我能够读取文件,获取位,但我在提取这些位时遇到问题。
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;
}
像素是无符号字符。我有调用extract()
和fputc(3)
返回值的循环。我觉得我从这些碎片中得到了垃圾。这导致我有大量 (1.5 gig) 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);
}