ここから拝借。
これ仕様書に載ってんのかなぁ?
$__crc32_table = [] # Lookup table array def __crc32_reflect(ref, ch) # Reflects CRC bits in the lookup table value = 0 # Swap bit 0 for bit 7, bit 1 for bit 6, etc. (1..ch).each do |i| if (ref & 1).nonzero? value |= (1 << (ch - i)) end ref = ((ref >> 1) & 0x7fffffff) end return value; end def __crc32_init_table() # Builds lookup table array # This is the official polynomial used by # CRC-32 in PKZip, WinZip and Ethernet. polynomial = 0x04c11db7; # 256 values representing ASCII character codes. 256.times do |i| $__crc32_table[i] = (__crc32_reflect(i, 8) << 24); 8.times do |j| $__crc32_table[i] = (($__crc32_table[i] << 1) ^ (($__crc32_table[i] & (1 << 31)).nonzero? ? polynomial : 0)) end $__crc32_table[i] = __crc32_reflect($__crc32_table[i], 32) end end __crc32_init_table() puts '%x' % $__crc32_table[?x]