简体   繁体   English

是否有一个python函数可将相同的结果传递给php.hash?

[英]Is there a python function for getting the same result to php.hash?

I want my Python crc32 function get the same result with PHP hash function. 我希望我的Python crc32函数与PHP hash函数获得相同的结果。 Where is the Python module in this world? 这个世界上的Python模块在哪里? My heart is almost collapsed at this moment. 此刻我的心几乎崩溃了。

The PHP function is: PHP函数是:

hexdec(hash('crc32', 'hi', false))

The Python function I used: 我使用的Python函数:

binascii.crc32('hi') & 0xffffffff

PHP: PHP:

<?php
function_exists('abs');
function_exists('hexdec');
function_exists('hash');
$hash = hexdec(hash('crc32', 'hi', false));
echo $hash. "\n";
?>

Output: 输出:

4049932203 4049932203

Python: 蟒蛇:

import binascii
binascii.crc32('hi') & 0xffffffff

Output: 输出:

3633523372 3633523372

Make sure to use the same hash algorithm. 确保使用相同的哈希算法。 For example: 例如:

PHP PHP

php > echo hash('sha512', 'foo'); php> echo hash('sha512', 'foo');

Result: 结果:

f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7

Python 蟒蛇

import hashlib hashlib.sha512(b'foo').hexdigest()

Result: f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7' 结果: f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM