私はステガノグラフィで遊んでいます。画像からテキストファイルをプルしようとしています。ファイルを読み取ってビットを取得することはできますが、これらのビットの抽出に問題があります。
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はunsignedcharです。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);
}