Skip to content

Commit

Permalink
更新webqq_hash函数
Browse files Browse the repository at this point in the history
  • Loading branch information
smallevilbeast committed Jun 14, 2014
1 parent bf21cc6 commit de9aa68
Showing 1 changed file with 83 additions and 55 deletions.
138 changes: 83 additions & 55 deletions twqq/_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
源在这里: http://pidginlwqq.sinaapp.com/hash.js
如果无法正常获取好友列表, 请查看上面js是否有更新, 有则更新本函数
Update On: 2013-12-11
Update On: 2014-06-15
"""
# def webqq_hash(b, i):
# if isinstance(b, basestring):
Expand Down Expand Up @@ -42,57 +42,85 @@
# return d


def webqq_hash(i, a):
if isinstance(i, (str, unicode)):
i = int(i)
class b:
def __init__(self, _b, i):
self.s = _b or 0
self.e = i or 0

r = [i >> 24 & 255, i >> 16 & 255, i >> 8 & 255, i & 255]

j = [ord(_a) for _a in a]

e = [b(0, len(j) - 1)]
while len(e) > 0:
c = e.pop()
if not (c.s >= c.e or c.s < 0 or c.e > len(j)):
if c.s+1 == c.e:
if (j[c.s] > j[c.e]) :
l = j[c.s]
j[c.s] = j[c.e]
j[c.e] = l
else:
l = c.s
J = c.e
f=j[c.s]
while c.s < c.e:
while c.s < c.e and j[c.e]>=f:
c.e -= 1
r[0] = r[0] + 3&255

if c.s < c.e:
j[c.s] = j[c.e]
c.s += 1
r[1] = r[1] * 13 + 43 & 255

while c.s < c.e and j[c.s] <= f:
c.s += 1
r[2] = r[2] - 3 & 255

if c.s < c.e:
j[c.e] = j[c.s]
c.e -= 1
r[3] = (r[0] ^ r[1]^r[2]^r[3]+1) & 255
j[c.s] = f
e.append(b(l, c.s-1))
e.append(b(c.s + 1, J))
j = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F"]
e = ""
for c in range(len(r)):
e += j[r[c]>>4&15]
e += j[r[c]&15]

return e
# def webqq_hash(i, a):
# if isinstance(i, (str, unicode)):
# i = int(i)
# class b:
# def __init__(self, _b, i):
# self.s = _b or 0
# self.e = i or 0

# r = [i >> 24 & 255, i >> 16 & 255, i >> 8 & 255, i & 255]

# j = [ord(_a) for _a in a]

# e = [b(0, len(j) - 1)]
# while len(e) > 0:
# c = e.pop()
# if not (c.s >= c.e or c.s < 0 or c.e > len(j)):
# if c.s+1 == c.e:
# if (j[c.s] > j[c.e]) :
# l = j[c.s]
# j[c.s] = j[c.e]
# j[c.e] = l
# else:
# l = c.s
# J = c.e
# f=j[c.s]
# while c.s < c.e:
# while c.s < c.e and j[c.e]>=f:
# c.e -= 1
# r[0] = r[0] + 3&255

# if c.s < c.e:
# j[c.s] = j[c.e]
# c.s += 1
# r[1] = r[1] * 13 + 43 & 255

# while c.s < c.e and j[c.s] <= f:
# c.s += 1
# r[2] = r[2] - 3 & 255

# if c.s < c.e:
# j[c.e] = j[c.s]
# c.e -= 1
# r[3] = (r[0] ^ r[1]^r[2]^r[3]+1) & 255
# j[c.s] = f
# e.append(b(l, c.s-1))
# e.append(b(c.s + 1, J))
# j = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
# "B", "C", "D", "E", "F"]
# e = ""
# for c in range(len(r)):
# e += j[r[c]>>4&15]
# e += j[r[c]&15]

# return e

def webqq_hash(b, j):
b = str(b)
a = j + "password error"
i = ""

while True:
if len(i) <= len(a):
i += b
if len(i) == len(a):
break
else:
i = i[:len(a)];
break

E = [0] * len(i)
c = 0
while c < len(i):
E[c] = ord(i[c]) ^ ord(a[c])
c += 1
a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
i = ""
c = 0
while c < len(E):
i += a[E[c] >> 4 & 15]
i += a[E[c] & 15]
c += 1
return i

0 comments on commit de9aa68

Please sign in to comment.