#!/usr/bin/env python

import struct
import sys


fp = open(sys.argv[1])
icontent = fp.read()
fp.close();

solutions = {}
for line in icontent.split("\n"):
    if not "<--" in line:
        continue
    k,s = line.split("<--")
    k,s = map(str.strip,[k,s])
    solutions[int(k,16)]=s


c_body_list = []
for k in xrange(0x80000):
    s = solutions[k]
    slist = [s[ci:ci+2] for ci in xrange(0,len(s),2)]
    c_line_str = "0x"+",0x".join(slist)+","+"//%05x" % k
    c_body_list.append(c_line_str)

header = "\nunsigned char backdoor_solutions[0x80000*5] = {\n"
footer = "\n};\n"
c_code = header+"\n".join(c_body_list)+footer

fp = open("backdoor_solutions.h","wb")
fp.write(c_code)
fp.close()

# use it to transform computed_sha1.txt (generated by compute_hash.py) to backdoor_solutions.h
