
Dec. 15, 1999
7:40 a.m.
[JimA posts his Python rendering of Gary Brown's code] Yup! That's the zip algorithm, right down to the absurdly bit-reversed polynomial.
def crc32(string): crc = 0xFFFFFFFF for ch in string: crc = crc_32_tab[((crc) ^ ord(ch)) & 0xff] ^ (((crc) >> 8) & 0xFFFFFF) return ~crc
Note that the last line is better (whether in Python or C!) as return crc ^ 0xffffffff Else you'll get a surprising result in a 64-bit Python, and in some 64-bit C implementations. it's-a-32-bit-algorithm-not-an-"int"-or-"long"-one-ly y'rs - tim