#!/usr/bin/python

import binascii
import re
from Crypto.Cipher import AES

cp_strings = [
		'6fe8131ca9b01ba011e9b0f5bc08c1c9ebaf65f039e1592d53a30def7fced26c',
		'd3802c10649503a60619b709d1278ffff84c1856dfd4097541d55c6740442d8b',
		'c402fb2f70c89a0df112c5e38583f9202a96c6de3fa1aa3da6849bb317a983b3',
		'e1a28374f5562768c061f22394a556a75860f132432415d67768e0c112c31495',
		'd3802c10649503a60619b709d1278efef84c1856dfd4097541d55c6740442d8b'
        ]

def hulu_decrypt_id(p):
    global cp_strings

    v3 = p.split("~")
    v3a = binascii.unhexlify(v3[0])
    v3b = binascii.unhexlify(v3[1])

    ecb = AES.new(v3b, AES.MODE_ECB)
    tmp = ecb.decrypt(v3a)

    for v1 in cp_strings[:]:
        ecb = AES.new(binascii.unhexlify(v1), AES.MODE_ECB)
        v2 = ecb.decrypt(tmp)
        if (re.search("[0-9A-Za-z_-]{32}", v2)):
            return v2

if __name__=="__main__":
    pid = "46fc4f0d4a15515e0a1090a2ece4918a04a70c31feb2c6f7d8d19b73a7f8717e~767ab4bb7950c065112579e2dfde374d60d22bb71ab013b86f9d853c45edf32d"
    # wanted = "2QpCmO87j4IL84l6feso4r6yU5EwVM8b"
    print hulu_decrypt_id( pid )
