-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrc.py
69 lines (49 loc) · 1.59 KB
/
crc.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
import random
import time, os
from datetime import datetime, date
#code translated from js
#right shift without sign extension
def rshift(val, n):
return val >> n if val >= 0 else (val+0x100000000)>>n
def getCRCTable():
signedTxHex = 0
signedTransactions = []
signedTransactionsCounter = 0
for signedTransactionsCounter in range(256):
signedTxHex = signedTransactionsCounter
tmp = 0
for tmp in range(8):
signedTxHex = 3988292384 ^ rshift(signedTxHex, 1) \
if signedTxHex & 1 \
else rshift(signedTxHex, 1)
signedTransactions.append(signedTxHex)
return signedTransactions
def crc(param):
crcTable = getCRCTable()
crc = 0 ^ -1
for i in range(len(param)):
index = (crc ^ ord(param[i])) & 255
crc = rshift(crc, 8) ^ crcTable[index]
return rshift((crc ^ -1), 0)
def api():
return "public-api"
def uuidv4():
mask = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
dialog_id = ""
for ch in mask:
if ch == 'x' or ch == 'y':
r = int(random.random() * 16) | 0
v = r if ch == 'x' else r & 3 | 8
dialog_id += format(v,'x')
else:
dialog_id += ch
return dialog_id
def getCRCSign(t):
return crc(f"{api()}{t}qVxRWnespIsJg7DxFbF6N9FiQR5cjnHyygru3JcToH4dPdiNH5SXOYIc00qMXPKJ")
def unix_time():
os.environ['TZ'] = 'Europe/Moscow'
time.tzset()
dt = datetime.today()
epoch = datetime.utcfromtimestamp(0)
delta = dt - epoch
return delta.total_seconds() * 1000 - 10**7