我正在尝试用CRC16/32校验和与binascii.crc32,binacsii.crc_hqx
这是我作为示例使用的值(我从我正在阅读的网络协议规范中获得了这个示例值)。
下面是具有上述测试值的测试代码。
>>> import binascii
>>> hex(binascii.crc_hqx("123456789", 0x0000))
'0x31c3' #corret result, same as test value result
>>> hex(binascii.crc32("123456789", 0x00000000) & 0xFFFFFFFF)
'0xcbf43926L'#Wrong result, different value from test value result, It Must be 0xd202d277什么问题.?
实际上,我在Python Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm.中找到了这个句子。
这是否意味着我不能将它用于CRC32校验和?
若然,是否有任何建议?
我自己也没做过测试。
我刚从一个解释CRC32的文档中得到了这些值。
下面是我引用的表

在包含图表的文档中,它描述的G2S_crc如下所示。
The CRC-32 polynomial defined for G2S can be described as follows:
x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
It is also represented as 0x04C11DB7. This polynomial is also used by IEEE 802.3.。
function crc(bit array bitString[1..len], int polynomial)
{
shiftRegister := initial value // either the seed or all 1 bits
for i from 1 to len
{
if most significant bit of shiftRegister = 1
{
// Shift left, place data bit as LSB, then divide
shiftRegister := shiftRegister left shift 1
shiftRegister := shiftRegister or bitString[i]
shiftRegister := shiftRegister xor polynomial
}
else
{
// shiftRegister is not divisible by polynomial yet.
// Just shift left and bring current data bit onto LSB of shiftRegister
shiftRegister := shiftRegister left shift 1
shiftRegister := shiftRegister or bitString[i]
}
}
return shiftRegister
}它和binascii不同吗?
发布于 2015-10-06 01:49:11
这个在线计算器
http://www.lammertbies.nl/comm/info/crc-calculation.html
同意Python

你能引用0xd202d277的来源吗?在位序等方面也有变化。
发布于 2016-08-13 20:49:02
从这个CRC目录中,您似乎在使用CRC目录而python使用普通的CRC32,带有polynom 0xEDB88320。
顺便说一下,python返回的CRC是一个int。python的int是签名的。如果需要无符号表示,就需要倒置结果,比如hex(~0x76e943d9 & 0xffffffff)。
https://stackoverflow.com/questions/32960363
复制相似问题