Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from binascii import a2b_hex, b2a_hex
- from Crypto.Hash import MD5
- from Crypto.Cipher import AES, Blowfish
- def genurlkey(songid, md5origin, mediaver=4, fmt=1):
- """ Calculate the deezer download url given the songid, origin and media+format """
- data = b'\xa4'.join(_.encode("utf-8") for _ in [md5origin, str(fmt), str(songid), str(mediaver)])
- data = b'\xa4'.join([md5hex(data), data])+b'\xa4'
- if len(data)%16:
- data += b'\x00' * (16-len(data)%16)
- return hexaescrypt(data, "jo6aey6haid2Teih").decode('utf-8')
- def md5hex(data):
- """ return hex string of md5 of the given string """
- h = MD5.new()
- h.update(data)
- return b2a_hex(h.digest())
- def hexaescrypt(data, key):
- """ returns hex string of aes encrypted data """
- c = AES.new(key, AES.MODE_ECB)
- return b2a_hex(c.encrypt(data))
- def calcbfkey(songid):
- """ Calculate the Blowfish decrypt key for a given songid """
- h = md5hex(b"%d" % songid)
- key = b"g4el58wc0zvf9na1"
- return "".join(chr(ord(h[i]) ^ ord(h[i+16]) ^ ord(key[i])) for i in range(16))
- def blowfishDecrypt(data, key):
- """ CBC decrypt data with key """
- c = Blowfish.new(key, Blowfish.MODE_CBC, a2b_hex("0001020304050607"))
- return c.decrypt(data)
Advertisement
Add Comment
Please, Sign In to add comment