Login
Immutable PageDiscussionInfoAttachments

Revision 1 as of 2014-12-10 02:21:02

Clear message
ytoku/CTF/Writeup/AdventCalendarCTF2014/2014-12-10

MMA

xor

問題

712249146f241d31651a504a1a7372384d173f7f790c2b115f47

Source Code:

   1 #include <stdio.h>
   2 #include <string.h>
   3 
   4 int main() {
   5   char flag[] = "ADCTF_XXXXXXXXXXXXXXXXXXXX";
   6   int len = strlen(flag);
   7   for (int i = 0; i < len; i++) {
   8     if (i > 0) flag[i] ^= flag[i-1];
   9     flag[i] ^= flag[i] >> 4;
  10     flag[i] ^= flag[i] >> 3;
  11     flag[i] ^= flag[i] >> 2;
  12     flag[i] ^= flag[i] >> 1;
  13     printf("%02x", (unsigned char)flag[i]);
  14   }
  15   return 0;
  16 }

メモ

解法

   1 #include <stdio.h>
   2 #include <string.h>
   3 
   4 int main() {
   5   char ct[] = "\x71\x22\x49\x14\x6f\x24\x1d\x31\x65\x1a\x50\x4a\x1a\x73\x72\x38\x4d\x17\x3f\x7f\x79\x0c\x2b\x11\x5f\x47";
   6   char flag[] = "ADCTF_XXXXXXXXXXXXXXXXXXXX";
   7   char pt[256];
   8   int len = strlen(flag);
   9   for (int i = 0; i < len; i++) {
  10     for (int c = 0; c < 256; c++) {
  11       flag[i] = c;
  12       if (i > 0) flag[i] ^= flag[i-1];
  13       flag[i] ^= flag[i] >> 4;
  14       flag[i] ^= flag[i] >> 3;
  15       flag[i] ^= flag[i] >> 2;
  16       flag[i] ^= flag[i] >> 1;
  17       if (flag[i] == ct[i]) {
  18         pt[i] = c;
  19         break;
  20       }
  21     }
  22   }
  23   pt[len] = 0;
  24   printf("%s", pt);
  25   return 0;
  26 }