[关闭]
@romangol 2015-09-22T22:22:11.000000Z 字数 580 阅读 2527

CSAW CTF 2015 Qualification Round - Crypto 500

CTF


  1. #include <stdio.h>
  2. #include <string>
  3. int main()
  4. {
  5. FILE * fp = fopen( "input", "rb");
  6. FILE * wp = fopen( "test.pdf", "wb");
  7. static unsigned char buffer[769180];
  8. unsigned char iv[4];
  9. unsigned char tmp[4];
  10. /*
  11. pdf = 0x25, 0x50, 0x44, 0x46
  12. iv = 0x43, 0x41, 0x53, 0x48
  13. header = 0x24, 0x58, 0x4d, 0x54
  14. key = pdf ^ iv ^ header
  15. */
  16. unsigned char key[4] = { 0x42, 0x49, 0x5a, 0x5a };
  17. fread( buffer, sizeof(buffer), 1, fp );
  18. iv[0] = 'C';
  19. iv[1] = 'A';
  20. iv[2] = 'S';
  21. iv[3] = 'H';
  22. for ( size_t i = 0; i < sizeof(buffer) / 4; ++i )
  23. {
  24. for ( size_t j = 0; j < 4; ++j )
  25. {
  26. tmp[j] = buffer[i * 4 + j] ^ iv [j] ^ key[j];
  27. iv[j] = buffer[i * 4 + j];
  28. }
  29. fwrite( tmp, 4, 1, wp );
  30. }
  31. fclose(fp);
  32. fclose(wp);
  33. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注