This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdecrypt.py
69 lines (57 loc) · 2.31 KB
/
decrypt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Code taken from
# https://github.com/vn-ki/anime-downloader
# All rights to Vishnunarayan K I
import base64
import sys
from hashlib import md5
from Cryptodome import Random
from Cryptodome.Cipher import AES
from requests.utils import quote
BLOCK_SIZE = 16
#KEY = b"LXgIVP&PorO68Rq7dTx8N^lP!Fa5sGJ^*XK"
KEY = b"267041df55ca2b36f2e322d05ee2c9cf"
# From stackoverflow https://stackoverflow.com/questions/36762098/how-to-decrypt-password-from-javascript-cryptojs-aes-encryptpassword-passphras
def pad(data):
length = BLOCK_SIZE - (len(data) % BLOCK_SIZE)
return data + (chr(length)*length).encode()
def unpad(data):
return data[:-(data[-1] if type(data[-1]) == int else ord(data[-1]))]
def bytes_to_key(data, salt, output=48):
# extended from https://gist.github.com/gsakkis/4546068
assert len(salt) == 8, len(salt)
data += salt
key = md5(data).digest()
final_key = key
while len(final_key) < output:
key = md5(key + data).digest()
final_key += key
return final_key[:output]
def decrypt(encrypted, passphrase):
encrypted = base64.b64decode(encrypted)
assert encrypted[0:8] == b"Salted__"
salt = encrypted[8:16]
key_iv = bytes_to_key(passphrase, salt, 32+16)
key = key_iv[:32]
iv = key_iv[32:]
aes = AES.new(key, AES.MODE_CBC, iv)
return unpad(aes.decrypt(encrypted[16:]))
def decrypt_export(url):
decrypt_ed = decrypt((url).encode('utf-8'), KEY).decode('utf-8').lstrip(' ')
escap_ed = quote(decrypt_ed, safe='~@#$&()*!+=:;,.?/\'')
return escap_ed
if __name__ == '__main__':
if sys.argv:
if len(sys.argv[1:]) > 1:
# sending a file_name as the argument
# e.g: python3 decrypt.py file_name.txt anything ...
file_name = sys.argv[1]
with open(file_name) as fn:
for l in fn.readlines():
decrypt_ed = decrypt(l.encode('utf-8'), KEY).decode('utf-8').lstrip(' ')
# https://stackoverflow.com/a/6618858/8608146
escap_ed = quote(decrypt_ed, safe='~@#$&()*!+=:;,.?/\'')
print(escap_ed)
elif len(sys.argv[1:]) == 1:
decrypt_ed = decrypt((sys.argv[1]).encode('utf-8'), KEY).decode('utf-8').lstrip(' ')
escap_ed = quote(decrypt_ed, safe='~@#$&()*!+=:;,.?/\'')
print(escap_ed)