Advertisement
sebbu

animelon decode

May 23rd, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. # https://animelon.com/api/languagevideo/findByVideo?videoId=5aac0620b6b8f36034bd33b8&learnerLanguage=en&subs=1&cdnLink=1&viewCounter=1
  5.  
  6. # https://www.openssl.org/docs/manmaster/man3/EVP_BytesToKey.html
  7. # http://joelinoff.com/blog/?p=885
  8. # http://downloads.joelinoff.com/mycrypt.py
  9. # https://stackoverflow.com/a/16761459/694473
  10. # https://crypto.stackexchange.com/a/35614
  11. # http://grepcode.com/file/repo1.maven.org/maven2/ca.juliusdavies/not-yet-commons-ssl/0.3.9/org/apache/commons/ssl/OpenSSL.java#469
  12. # https://stackoverflow.com/a/12221931/694473
  13. # https://stackoverflow.com/a/13923114/694473
  14.  
  15. import base64
  16. import json
  17. from Crypto.Cipher import AES
  18. from hashlib import md5
  19. import binascii
  20.  
  21. def derive_key_and_iv(password, salt, key_length, iv_length):
  22.     d = d_i = ''.encode('cp437', 'ignore')
  23.     while len(d) < key_length + iv_length:
  24.         d_i = md5(d_i + password + salt).digest().decode('cp437', 'ignore').encode('cp437', 'ignore')
  25.         d += d_i
  26.     return d[:key_length], d[key_length:key_length+iv_length]
  27.  
  28. with open('bla.json') as f:
  29.     jcon = json.load(f)
  30.     bla = jcon['resObj']['subtitles'][4]['content']['romajiSub']
  31.     blo = base64.b64decode(bla[8:-5])
  32.     with open('bla.enc', 'wb') as f1:
  33.         f1.write(blo)
  34.    
  35.     pwd = bla[0:8][::-1]
  36.     #pwd = bla[7::-1]
  37.     with open('key.txt', 'w') as f2:
  38.         f2.write(pwd)
  39.     pwd = pwd.encode('ascii', 'ignore') # otherwise cause issues with MD5 digest
  40.     print("passphrase : %s" % pwd)
  41.    
  42.     salt=blo[8:16]
  43.     salt2 = binascii.hexlify(salt).decode()
  44.     with open('salt.txt', 'w') as f3:
  45.         f3.write(salt2)
  46.     print("salt : %s" % salt2)
  47.    
  48.     key_length = 32
  49.     bs = AES.block_size # 16
  50.     pwd = pwd.decode('cp437', 'ignore').encode('cp437', 'ignore')
  51.     salt = salt.decode('cp437', 'ignore').encode('cp437', 'ignore')
  52.     key, iv = derive_key_and_iv(pwd, salt, key_length, bs)
  53.    
  54.     key2 = binascii.hexlify(key)
  55.     iv2 = binascii.hexlify(iv)
  56.     print("key : %s" % key2)
  57.     print("iv : %s" % iv2)
  58.    
  59.     cipher = AES.new(key, AES.MODE_CBC, iv)
  60.     msg = cipher.decrypt(blo[16:])
  61.    
  62.     with open('bla.srt', 'wb') as f4:
  63.         f4.write(msg)
  64.  
  65. #with open('bla.json') as f:
  66. #   jcon = json.load(f)
  67. #   bla = jcon['resObj']['subtitles'][4]['content']['romajiAndTimes']
  68. #   for item in bla:
  69. #       print(item['startTime'], ' '.join(item['tokenized']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement