Guest User

Untitled

a guest
Dec 9th, 2016
420
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from binascii import a2b_hex, b2a_hex
  2. from Crypto.Hash import MD5
  3. from Crypto.Cipher import AES, Blowfish
  4.  
  5. def genurlkey(songid, md5origin, mediaver=4, fmt=1):
  6. """ Calculate the deezer download url given the songid, origin and media+format """
  7. data = b'\xa4'.join(_.encode("utf-8") for _ in [md5origin, str(fmt), str(songid), str(mediaver)])
  8. data = b'\xa4'.join([md5hex(data), data])+b'\xa4'
  9. if len(data)%16:
  10. data += b'\x00' * (16-len(data)%16)
  11. return hexaescrypt(data, "jo6aey6haid2Teih").decode('utf-8')
  12.  
  13.  
  14. def md5hex(data):
  15. """ return hex string of md5 of the given string """
  16. h = MD5.new()
  17. h.update(data)
  18. return b2a_hex(h.digest())
  19.  
  20. def hexaescrypt(data, key):
  21. """ returns hex string of aes encrypted data """
  22. c = AES.new(key, AES.MODE_ECB)
  23. return b2a_hex(c.encrypt(data))
  24.  
  25. def calcbfkey(songid):
  26. """ Calculate the Blowfish decrypt key for a given songid """
  27. h = md5hex(b"%d" % songid)
  28. key = b"g4el58wc0zvf9na1"
  29. return "".join(chr(ord(h[i]) ^ ord(h[i+16]) ^ ord(key[i])) for i in range(16))
  30.  
  31. def blowfishDecrypt(data, key):
  32. """ CBC decrypt data with key """
  33. c = Blowfish.new(key, Blowfish.MODE_CBC, a2b_hex("0001020304050607"))
  34. return c.decrypt(data)
Advertisement
Add Comment
Please, Sign In to add comment