SHARE
TWEET

GCHQ CanYouCrackIt Stage 2 - C implementation of VM code

a guest Dec 8th, 2011 563 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2.  
  3.  
  4. char buf[4096];
  5.  
  6. void decrypt(char *mem, int len, char initial, char step) {
  7.   int i=0;
  8.   char x = initial;
  9.   for(i=0; i<len; i++)
  10.   {
  11.     mem[i] ^= x;
  12.     x+=step;
  13.   }
  14. }
  15.  
  16. int main() {
  17.   int i=0;
  18. // decode next decrypt code
  19.   FILE *in = fopen("initial", "r");
  20.   fread(buf, 4096, 1, in);
  21.  
  22.   decrypt(buf+0x100, 0x80, 170, 1); // decrypt first decryptor at 0x100
  23.   decrypt(buf+0x1c0, 0x1F2 - 0x1C0, 50, 3); // decrypt get string
  24.  
  25. //dump memory
  26.   for(i = 0; i<4096; i++)
  27.     printf("%c", buf[i]);
  28. }
  29.  
RAW Paste Data
Top