【发布时间】:2017-08-02 13:25:45
【问题描述】:
crc_table = None
def make_crc_table():
global crc_table
crc_table = [0] * 256
for n in xrange(256):
c = n
for k in xrange(8):
if c & 1:
c = 0xedb88320L ^ (c >> 1)
else:
c = c >> 1
crc_table[n] = c
make_crc_table()
"""
/* Update a running CRC with the bytes buf[0..len-1]--the CRC
should be initialized to all 1's, and the transmitted value
is the 1's complement of the final running CRC (see the
crc() routine below)). */
"""
def update_crc(crc, buf):
c = crc
for byte in buf:
c = crc_table[int((c ^ ord(byte)) & 0xff)] ^ (c >> 8)
return c
# /* Return the CRC of the bytes buf[0..len-1]. */
def crc(buf):
return update_crc(0xffffffffL, buf) ^ 0xffffffffL
我使用此代码计算 png crc 值
我的 IHDR 块数据是 000008A0 000002FA 08020000 00,该代码的结果是 0xa1565b1L
然而真正的 crc 是0x84E42B87。我用众所周知的 png 检查工具检查了这个值,正确的 crc 是 0x84E42B87。
我不明白这个值是如何计算的和正确的值。
【问题讨论】:
标签: python image image-processing crc crc32