0
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
を計算するためにどのように私は
マイIHDRチャンクデータが000008A0 000002FA 08020000 00
あるPNG CRC値を計算するためにこのコードを使用して、実際のCRCが0x84E42B87
だったしかしそのコードの結果は0xa1565b1L
ました。私はよく知られているpngチェッカーツールでこの値をチェックし、正しいcrcは0x84E42B87
でした。
この値がどのように計算され、正しい値であるかはわかりません。Pythonは:PNG CRC値