我正在玩弄隱寫術。我正試圖從圖像中拉出一個文本文件。我能夠讀取文件,獲取這些位,但是我在提取這些位時遇到了問題。位提取和隱寫術
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演出)的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);
}
速記或**隱寫術**? –
顯示調用提取的循環 - 因爲您應該證明您正在循環顯示圖像。 – borrible
@borrible我包含了循環 –