-
Notifications
You must be signed in to change notification settings - Fork 3
/
sign.py
52 lines (44 loc) · 998 Bytes
/
sign.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
import base64
import hashlib
import error
__all__ = ['GetMethod']
__MAP__ = {}
def register(md5):
def wrapper(func):
__MAP__[md5] = func
return func
return wrapper
def simpleMD5(content):
return hashlib.md5(content.encode('ascii')).hexdigest()
def GetMethod(content):
md5 = simpleMD5(content)
if md5 in __MAP__:
return __MAP__[md5]
else:
raise error.NoSuchSignFunc
@register('c90ac3b782027c99149c999d74be925f')
def __sign1(sign3,sign1):
a = {}
p = {}
o = []
for i in range(256):
a[i] = ord(sign3[i % len(sign3)])
p[i] = i
u = 0
for i in range(256):
u = (u + p[i] + a[i]) % 256
p[u],p[i] = p[i],p[u]
j,u = 0,0
for i in range(len(sign1)):
j = (j + 1) % 256;
u = (u + p[j]) % 256;
p[u],p[j] = p[j],p[u]
k = p[(p[j] + p[u]) % 256]
# print(k)
o.append(ord(sign1[i]) ^ k) # 异或
return base64.b64encode(bytes(o)).decode('ascii')
# @register(simpleMD5('test'))
# def __test():
# pass
# if __name__ == '__main__':
# print(GetMethod('test') == __test)