#!/usr/bin/env python

import binascii
import hashlib
import base64
import sys

salt ='\x7c\x62\x76\xc2\x7f\xf9\x5a\x5c\xea\x42\x80\xde\x08\x0d\xa4\x5c'

def utf16tobin(s):
      return s.encode('hex')[4:].decode('hex')

def gethash(password):
    m = hashlib.sha1()
    m.update(salt)
    password = password.encode("utf-16")
    password = utf16tobin(password)
    m.update(password)
    #return m.hexdigest()
    return m.digest()

if len(sys.argv) < 2:
    print >> sys.stderr, "Usage: %s <dictionary file>" % sys.argv[0]
    sys.exit(-1)

count = 0
with open(sys.argv[1]) as f:
    for line in f.readlines():
        line = line.rstrip()
        if line.startswith('#'):
            continue
        print "test-%d:$episerver$*0*%s*%s" % (count, base64.b64encode(salt), base64.b64encode(gethash(line)))
        count += 1

