binascii.crc32结果不匹配 [英] binascii.crc32 results not matching

查看:324
本文介绍了binascii.crc32结果不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取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


提前致谢,

问候,

拉里贝茨

解决方案

[Larry Bates]

我正在尝试将binascii.crc32的结果与其他实用程序的结果相匹配
32位无符号CRC。 binascii.crc32返回结果范围为-2 ** 31-1和2 ** 21-1。有没有人曾经做过任何苦涩的事情。代码从binascii.crc32获得正确的无符号32位结果?


只是& 0xffffffff(一个32位1位的字符串)的结果。

从三个文件的测试输出剪辑:

binascii.crc32 = -1412119273,oldcrc32 = 2221277246
binascii.crc32 = -647246320,oldcrc32 = 73793598
binascii.crc32 = -1391482316,oldcrc32 = 79075810




看起来这些都不是使用相同的CRC算法(有许多不同的方法来计算32位CRC)。例如,

print -1412119273& 0xffffffff



2882848023

且不等于2221277246.或者你在Windows,并忘了

以二进制模式打开文件。或者某事;-)


Larry Bates写道:

我正在尝试将binascii.crc32的结果发送到匹配产生
32位无符号CRC的另一个实用程序的结果。




还有什么其他实用工具?正如蒂姆所说,有很多CRC32 ...

关于这个的背景说明偶然发现在

列表的顶部,以回应谷歌搜索 zip文件crc32校验和多项式,

虽然我确定有更简单的方法。 binascii文档说它的CRC32

与Zip文件校验和兼容,但它们没有描述它

进一步。


一般来说,CRC是用它们的多项式来描述的,虽然只是引用它不足以描述它们的行为,但如果你发生了b $ b碰巧知道你的实用程序的多项式,其他人可以

可能会指向一个更合适的例行程序,或者或许解释如果binascii实际是正确的..


-Peter


Peter Hansen写道:

Larry Bates写道:

我正在尝试获取binascii.crc32的结果,以匹配产生32位无符号CRC的另一个实用程序的结果。



还有哪些实用工具?正如蒂姆所说,有很多CRC32 ......关于这个的背景说明偶然发现在
列表的顶部,以回应谷歌搜索zip文件crc32校验和多项式,<虽然我确信有更简单的方法。 binascii文档说它的CRC32
与Zip文件校验和兼容,但它们没有进一步描述它。

一般来说,CRC是用它们的多项式,虽然只是引用它不足以描述它们的行为,但如果你碰巧知道你的实用程序的多项式,别人可能会指出你更多适当的例程,或者解释如果binascii实际上是正确的那个你做错了什么..

-Peter




查看以下单元测试。

http: //sourceforge.net/projects/crcmod/

我遇到了很多麻烦,以使结果与

的结果一致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

解决方案

[Larry Bates]

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?
Just "&" the result with 0xffffffff (a string of 32 1-bits).
Output snip from test on three files:

binascii.crc32=-1412119273, oldcrc32= 2221277246
binascii.crc32=-647246320, oldcrc32=73793598
binascii.crc32=-1391482316, oldcrc32=79075810



Doesn''t look like these are using the same CRC algorithms (there are
many distinct ways to compute a 32-bit CRC). For example,

print -1412119273 & 0xffffffff


2882848023

and that''s not equal to 2221277246. Or you''re on Windows, and forgot
to open the files in binary mode. Or something ;-)


Larry Bates wrote:

I''m trying to get the results of binascii.crc32
to match the results of another utility that produces
32 bit unsigned CRCs.



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


Peter Hansen wrote:

Larry Bates wrote:

I''m trying to get the results of binascii.crc32
to match the results of another utility that produces
32 bit unsigned CRCs.


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结果不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆