问题描述
我正在尝试获取binascii.crc32
的结果,以匹配生成
32位无符号CRC的另一个实用程序的结果。 binascii.crc32返回
结果范围为-2 ** 31-1和2 ** 21-1。
任何人都曾经解决过任何bit twddling的问题。从binascii.crc32获得一个正确的无符号32位结果的代码?
从三个文件的测试输出剪辑:
binascii.crc32 = -1412119273,oldcrc32 = 2221277246
binascii.crc32 = -647246320,oldcrc32 = 73793598
binascii.crc32 = -1391482316,oldcrc32 = 79075810
提前致谢,
问候,
拉里贝茨
看起来这些都不是使用相同的CRC算法(有许多不同的方法来计算32位CRC)。例如,
2882848023
且不等于2221277246.或者你在Windows,并忘了
以二进制模式打开文件。或者某事;-)
还有什么其他实用工具?正如蒂姆所说,有很多CRC32 ...
关于这个的背景说明偶然发现在
列表的顶部,以回应谷歌搜索 zip文件crc32校验和多项式,
虽然我确定有更简单的方法。 binascii文档说它的CRC32
与Zip文件校验和兼容,但它们没有描述它
进一步。
一般来说,CRC是用它们的多项式来描述的,虽然只是引用它不足以描述它们的行为,但如果你发生了b $ b碰巧知道你的实用程序的多项式,其他人可以
可能会指向一个更合适的例行程序,或者或许解释如果binascii实际是正确的..
-Peter
还有哪些实用工具?正如蒂姆所说,有很多CRC32 ......关于这个的背景说明偶然发现在
列表的顶部,以回应谷歌搜索zip文件crc32校验和多项式,与Zip文件校验和兼容,但它们没有进一步描述它。
一般来说,CRC是用它们的多项式,虽然只是引用它不足以描述它们的行为,但如果你碰巧知道你的实用程序的多项式,别人可能会指出你更多适当的例程,或者解释如果binascii实际上是正确的那个你做错了什么..
-Peter
查看以下单元测试。
我遇到了很多麻烦,以使结果与
的结果一致binascii.crc32。正如您将看到的,即使您获得多项式和位顺序正确,也会有一些额外的操作
。
Ray
I''m trying to get the results of binascii.crc32
to match the results of another utility that produces
32 bit unsigned CRCs. binascii.crc32 returns
results in the range of -2**31-1 and 2**21-1. Has
anyone ever worked out any "bit twiddling" code to
get a proper unsigned 32 bit result from binascii.crc32?
Output snip from test on three files:
binascii.crc32=-1412119273, oldcrc32= 2221277246
binascii.crc32=-647246320, oldcrc32=73793598
binascii.crc32=-1391482316, oldcrc32=79075810
Thanks in advance,
Regards,
Larry Bates
Doesn''t look like these are using the same CRC algorithms (there are
many distinct ways to compute a 32-bit CRC). For example,
2882848023
and that''s not equal to 2221277246. Or you''re on Windows, and forgot
to open the files in binary mode. Or something ;-)
What other utility? As Tim says, there are many CRC32s... the
background notes on this one happen to stumble out at the top of the
list in response to googling for "zip file crc32 checksum polynomial",
though I''m sure there are easier ways. The binascii docs say its CRC32
is compatible with the Zip file checksum, but they don''t describe it
further.
Generally CRCs are described in terms of their "polynomial", though just
quoting that isn''t sufficient to describe their behaviour, but if you
happen to know the polynomial for your utility, someone else can
probably point you to a more appropriate routine, or perhaps explain
what you were doing wrong if the binascii one is actually the right one..
-Peter
What other utility? As Tim says, there are many CRC32s... the
background notes on this one happen to stumble out at the top of the
list in response to googling for "zip file crc32 checksum polynomial",
though I''m sure there are easier ways. The binascii docs say its CRC32
is compatible with the Zip file checksum, but they don''t describe it
further.
Generally CRCs are described in terms of their "polynomial", though just
quoting that isn''t sufficient to describe their behaviour, but if you
happen to know the polynomial for your utility, someone else can
probably point you to a more appropriate routine, or perhaps explain
what you were doing wrong if the binascii one is actually the right one..
-Peter
Check out the unit test in the following.
http://sourceforge.net/projects/crcmod/
I went to a lot of trouble to get the results to match the results of
binascii.crc32. As you will see, there are a couple of extra operations
even after you get the polynomial and bit ordering correct.
Ray
这篇关于binascii.crc32结果不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!