我正在尝试将 md5hash 函数从 php 重写为 python3.2 但它是错误的:
php代码:
function MD5Hash($str) {
$m = md5($str);
$s = '';
foreach(explode("\n", trim(chunk_split($m, 2))) as $h) {
$s .= chr(hexdec($h));
}
return $s;
}
和python代码:
def md5hash(self, st):
m = hashlib.md5(st).hexdigest()
print(str(st) +" : "+m)
s = bytes()
for i in range(0, len(m), 2):
s += chr(int(m[i:min(i+2, len(m))], 16)).encode('utf-8')
return s
我正在尝试
PHP:
echo(base64_encode(MD5Hash(MD5Hash("123123"))));
result: KXJU6b/guPOcaC7aMLub4A==
Python:
print(base64.b64encode(self.md5hash(self.md5hash(b"123123"))))
result: fcOsw6VSwo5iHEvCjz98w7JMW09w
我不知道如何解决它,请帮助我:(