SHARE
TWEET

ructf 2014 reversing 500

tunz Mar 10th, 2014 33 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from struct import *
  2. import sys
  3.  
  4. key1 = "86DE9AF8DFF585E9DD85EF".decode('hex')
  5.  
  6. def encode(data,n):
  7.         global key1
  8.         zero_to_100 = []
  9.         i =0
  10.         while i<0x100:
  11.                 zero_to_100.append(i)
  12.                 i+=1
  13.         temp_key1 = list(key1)
  14.         temp_key = [chr(ord(i) ^ n) for i in key1]
  15.         calc_key1 = "".join(temp_key)
  16.  
  17.         i = 0
  18.         v4 = 0
  19.         v8 = 0
  20.         v3 = 0
  21.         while i<0x100:
  22.                 v3 += (zero_to_100[i] + ord(calc_key1[i % 0xB]))
  23.                 v3 = v3 & 0xFF
  24.                 v8 = zero_to_100[i]
  25.                 zero_to_100[i] = zero_to_100[v3]
  26.                 zero_to_100[v3] = v8
  27.                 i+=1
  28.  
  29.         i=0
  30.         v9 = 0
  31.         v10 = 0
  32.         answer = ""
  33.         while i < 0x20:
  34.                 v12 = v10+1
  35.                 v17 = v12
  36.                 v9 += zero_to_100[v12]
  37.                 v9 = v9 & 0xFF
  38.                 v13 = zero_to_100[v12]
  39.                 v15 = zero_to_100[v9]
  40.                 zero_to_100[v12] = v15
  41.                 zero_to_100[v9] = v13
  42.                 k = zero_to_100[(v13 + v15) & 0xFF]
  43.                 answer += chr(ord(data[i]) ^ k)
  44.                 v10 = v17
  45.                 i+=1
  46.  
  47.         return answer
  48.  
  49. def check(data):
  50.         data = list(data)
  51.         for i in data:
  52.                 if ord(i) < 0x20 or ord(i) >= 0x80:
  53.                         return False
  54.  
  55.         return True
  56.  
  57. compare = ""
  58. compare += pack('<L', 0x03C7C8CA)
  59. compare += pack('<L', 0x1F2810FC)
  60. compare += pack('<L', 0x948C7F7A)
  61. compare += pack('<L', 0x2469F92E)
  62. compare += pack('<L', 0xC1277D9F)
  63. compare += pack('<L', 0x7F4509C4)
  64. compare += pack('<L', 0x9745EE75)
  65. compare += pack('<L', 0x1F79AF8D)
  66.  
  67. for n in range(0,0x100):
  68.         xored = encode("1"*32,n)
  69.  
  70.         key = ""
  71.         for i in xored:
  72.                 key += chr(ord(i) ^ ord('1'))
  73.  
  74.         i=0
  75.         answer = ""
  76.         while i< 32:
  77.                 answer += chr(ord(key[i]) ^ ord(compare[i]))
  78.                 i+=1
  79.  
  80.         if check(answer):
  81.                 print answer
  82.                 sys.exit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top