@romangol
2015-09-22T22:22:11.000000Z
字数 580
阅读 2527
CTF
#include <stdio.h>
#include <string>
int main()
{
FILE * fp = fopen( "input", "rb");
FILE * wp = fopen( "test.pdf", "wb");
static unsigned char buffer[769180];
unsigned char iv[4];
unsigned char tmp[4];
/*
pdf = 0x25, 0x50, 0x44, 0x46
iv = 0x43, 0x41, 0x53, 0x48
header = 0x24, 0x58, 0x4d, 0x54
key = pdf ^ iv ^ header
*/
unsigned char key[4] = { 0x42, 0x49, 0x5a, 0x5a };
fread( buffer, sizeof(buffer), 1, fp );
iv[0] = 'C';
iv[1] = 'A';
iv[2] = 'S';
iv[3] = 'H';
for ( size_t i = 0; i < sizeof(buffer) / 4; ++i )
{
for ( size_t j = 0; j < 4; ++j )
{
tmp[j] = buffer[i * 4 + j] ^ iv [j] ^ key[j];
iv[j] = buffer[i * 4 + j];
}
fwrite( tmp, 4, 1, wp );
}
fclose(fp);
fclose(wp);
}