-
Notifications
You must be signed in to change notification settings - Fork 4
/
encrypt.py
160 lines (147 loc) · 4.75 KB
/
encrypt.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#coding:utf-8
import hashlib
def md5(strvalue):
#return hashlib.md5(strvalue.encode("ISO-8859-1") ).hexdigest()
return hashlib.md5(strvalue).hexdigest()
def hexchar2bin(strvalue):
temp = ''
for i in range(0, len(strvalue), 2):
temp += chr(int(strvalue[i:i+2],16))
return temp
def uin2hex(strvalue):
maxLength = 16
tempstr = int(strvalue, 10)
hexstrvalue = hex(tempstr).replace('0x','')
hexlength = len(hexstrvalue)
for i in range(maxLength - hexlength):
hexstrvalue = "0" + hexstrvalue
result = ''
for j in range(0, maxLength, 2):
result += hexstrvalue[j:j+2]
return result
def encrypt(password, uin, verifycode):
# 结果=MD5(MD5(hexchar2bin(MD5(密码))+pt.uin)+大写验证码)
# pt.uin,我们将\x00\x00\x00\x00\x3c\xcb\x48\x45分为00 00 00 00 3c cb 48 45
# 然后对每组16进制数字转换成ASCII字符,然后连接起来就是pt.uin
uin = hexchar2bin(uin2hex(uin))
I = password
F = hexchar2bin(md5(I))
E = md5(F+uin).upper()
D = md5(E+verifycode.upper()).upper()
return D
def getHash1(a,e):
c = []
for i in a:
c.append(int(i))
b = 0
k = -1
for i in c:
b += i
b %= len(e)
f = 0
if (b + 4 > len(e)):
h = 0
g = 4 + b - len(e)
while h < 4:
if h < g:
f |= (ord(e[b + h]) & 255) << (3 - h) * 8
else:
f |= (ord(e[h - g]) & 255) << (3 - h) * 8
h += 1
else:
h = 0
while h < 4:
f |= (ord(e[b + h]) & 255) << (3 - h) * 8
h += 1
# print i,f
k ^= f
c = [k >> 24 & 255,k >> 16 & 255,k >> 8 & 255,k & 255]
k = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
d = ""
b = 0
while b < len(c):
d += k[c[b] >> 4 & 15]
d += k[c[b] & 15]
b += 1
return d
#加密文件地址http://0.web.qstatic.com/webqqpic/pubapps/0/50/eqq.all.js,搜索function(b,i
def getHash2(qq, ptwebqq):
a = ptwebqq + 'password error'
s = ''
j = []
while True:
if (len(s) <= len(a)):
s += qq
if (len(s) == len(a)):
break
else:
s = s[0:len(a)]
break
for d in xrange(len(s)):
j.append(ord(s[d]) ^ ord(a[d]))
a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
s = ""
for d in xrange(len(j)):
s += a[j[d] >> 4 & 15]
s += a[j[d] & 15]
return s
def getHash3(b,i):
a=[]
s=0
for s in range(0,len(b)):
t=int(b[s])
a.append(t)
j = 0
d = -1
s = 0
for s in range(0,len(a)):
j = j + a[s]
j = j % len(i)
c = 0
if (j + 4) > len(i):
l = 4 + j - len(i)
for x in range(0,4):
if x < l:
c = c | (( ord(i[j + x]) & 255) << (3 - x) * 8 )
else:
c = c | ( ( ord(i[x - l]) & 255) << (3 - x) * 8 )
else:
for x in range(0,4):
c = c | (( ord(i[j + x]) & 255) << (3 - x) * 8 )
d = d ^ c
a = [0,0,0,0]
a[0] = d >> 24 & 255
a[1] = d >> 16 & 255
a[2] = d >> 8 & 255
a[3] = d & 255
d = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
s = ""
for j in range(0,len(a)):
s = s + d[a[j] >> 4 & 15]
s = s + d[a[j] & 15]
return s
def get_hash(qq, ptwebqq):
return getHash3(qq, ptwebqq)
password = 'wr6740495'
uin = '1213247447'
verifycode = '!IAC'
#F8F6ACAC
vfwebqq = '9a8d442b02dbde99248a85eb59aababc5f48785c48b74ca70be3962d3a5537ebdc330f66595221a2'
#print get_hash(uin, vfwebqq)
#print get_hash('195','5b5cecfea030bc7f06aad2ca6f650d059334a3d152fba9926bd82717188c3b66')
#{"h":"hello","hash":"F7F8A4FD","vfwebqq":"7e42206c73c8c4b526408e749537ec437eee9f39a89441d97573038296159ea24ad171a17ff102b9"}
ptwebqq = '7c07d3ddf87573ac01067b2e36ff0e8633aca9c64af1a99f3d789b30e9e546f7'
#print getHash2(uin, ptwebqq)
#print getHash3(uin, ptwebqq)
#print get_hash(uin, '7e42206c73c8c4b526408e749537ec437eee9f39a89441d97573038296159ea24ad171a17ff102b9')
# print uin2hex(uin)
# print hexchar2bin(uin2hex(uin))
# print hexchar2bin(md5(password))
# uin = hexchar2bin(uin2hex(uin))
# I = password
# F = hexchar2bin(md5(I))
# E = md5(F+uin).upper()
# D = md5(E+verifycode.upper()).upper()
# print md5(F+uin)
# print D
# print encrypt(password, uin, verifycode)