У меня есть небольшая программа, которая пытается сгенерировать определенное хеш-значение для сайта (Path of Exile Passive Tree).
Вот мой код:
####### ByteEncoder.py (This is a python convert from the official js code )
class ByteEncoder:
def __init__(self):
self.dataString = ""
def intToBytes(self, t, n=4):
t = int(t)
i = [None] * n
s = n - 1
while True:
i[s] = 255 & t
t = t>>8
s -= 1
if s < 0:
break
return i
def appendInt(self, t, n):
i = self.intToBytes(t,n)
for r in range(0, n):
self.dataString += chr(i[r])
def appendInt8(self, t):
self.appendInt(t, 1)
def appendInt16(self, t):
self.appendInt(t, 2)
def getDataString(self):
return self.dataString
##### main.py
hashes = [465, 45035]
encoder = ByteEncoder()
encoder.appendInt(4,4) # Tree Version
encoder.appendInt8(2) # Class ID
encoder.appendInt8(0) # Ascendency class
encoder.appendInt8(1) # Fullscreen
for h in hashes:
encoder.appendInt16(h)
d = str(base64.b64encode(bytes(encoder.getDataString(),encoding='utf8')))
d = d.replace("+", "-").replace("/", "_")
print(d)
Я получаю хэш AAAABAIAAQHDkcKvw6s =, но я должен получить AAAABAIAAQHRr-s =
Может кто-нибудь сказать мне, почему?
Если вы хотите проверить это
Что я хочу:
https://www.pathofexile.com/fullscreen-passive-skill-tree/3.6.6/AAAABAIAAQHRr-s=
Что я получу:
https://www.pathofexile.com/fullscreen-passive-skill-tree/3.6.6/AAAABAIAAQHDkcKvw6s=
Вот ответчик из комментария Виктор .
Просто используйте base64.urlsafe_b64encode()