forked from athrowaway2021/comix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comix_key.py
46 lines (34 loc) · 1.01 KB
/
comix_key.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
import base64
import binascii
import hashlib
def hash(a):
return binascii.hexlify(hashlib.md5(a).digest()).decode("utf-8").lower()
def reverse(a):
i = 0
for l in range(len(a) - 1, i, -1):
b = a[l]
a[l] = a[i]
a[i] = b
i += 1
return a
def expand(a):
l = len(a) * 2
k = len(a)
b = bytearray(l)
b[:k] = a[:k]
for j in range(len(a), l, 1):
k -= 1
b[j] = b[k]
return b
def calculate_key(digest, item_id, version, publisher_id, index):
i = int(publisher_id) + 1
if item_id % 2 == 0:
i += 1
data_to_hash = str(index % 10).encode() + version[::-1].encode() + str(item_id % 10).encode() + str(index * i).encode() + digest + version.encode() + str(int(publisher_id) % 10).encode()
e = expand(data_to_hash)
b = index % 256
for j in range(0, len(e), 1):
e[j] = e[j] ^ b
a = hash(e)
e = reverse(e)
return base64.b64encode((a + hash(e)).encode())[:50]