import hashlib import random import struct import sys import zlib def part1(): return list(hashlib.md5(teamname).hexdigest()[:8]) def part2(name): random.seed(name) chrset = '0123456789abcdef' return [chrset[random.randint(0, 15)] for x in xrange(8)][::-1] def part3(): name = (teamname + 'w00p')[:4].encode('hex') for x in xrange(4): data[x] = name[x*2:x*2+2] def part4(): crc = struct.pack('I', zlib.crc32('tulband') & 0xffffffff).encode('hex') for x in xrange(4): if flag[16+x*4+1] != crc[x] or flag[16+x*4+2] != crc[x+1]: return False return True if __name__ == '__main__': if len(sys.argv) != 3: print 'Usage: python %s ' % sys.argv[0] exit(0) if len(sys.argv[2]) != 32: print 'Incorrect Key Length' exit(0) teamname = sys.argv[1] flag = sys.argv[2] data = {} part3() if part1() == [flag[x*4] for x in xrange(8)] and \ part2(teamname) == [flag[x*4+3] for x in xrange(8)][::-1] and \ data == dict((x, flag[x*4+1:x*4+3]) for x in xrange(4)) and \ part4(): print '[x] Correct Flag' print '[+] Now submit it' else: print '[-] Incorrect Flag'