lib/digest/crc32_xfer.rb in digest-crc-0.5.0 vs lib/digest/crc32_xfer.rb in digest-crc-0.5.1
- old
+ new
@@ -1,14 +1,18 @@
require 'digest/crc32'
module Digest
+ #
+ # Implements the CRC32 XFER algorithm.
+ #
class CRC32XFER < CRC32
INIT_CRC = 0x00000000
XOR_MASK = 0x00000000
+ # Generated by `./pycrc.py --algorithm=table-driven --model=xfer --generate=c`
TABLE = [
0x00000000, 0x000000af, 0x0000015e, 0x000001f1, 0x000002bc, 0x00000213, 0x000003e2, 0x0000034d,
0x00000578, 0x000005d7, 0x00000426, 0x00000489, 0x000007c4, 0x0000076b, 0x0000069a, 0x00000635,
0x00000af0, 0x00000a5f, 0x00000bae, 0x00000b01, 0x0000084c, 0x000008e3, 0x00000912, 0x000009bd,
0x00000f88, 0x00000f27, 0x00000ed6, 0x00000e79, 0x00000d34, 0x00000d9b, 0x00000c6a, 0x00000cc5,
@@ -38,11 +42,17 @@
0x000073c8, 0x00007367, 0x00007296, 0x00007239, 0x00007174, 0x000071db, 0x0000702a, 0x00007085,
0x000069a0, 0x0000690f, 0x000068fe, 0x00006851, 0x00006b1c, 0x00006bb3, 0x00006a42, 0x00006aed,
0x00006cd8, 0x00006c77, 0x00006d86, 0x00006d29, 0x00006e64, 0x00006ecb, 0x00006f3a, 0x00006f95,
0x00006350, 0x000063ff, 0x0000620e, 0x000062a1, 0x000061ec, 0x00006143, 0x000060b2, 0x0000601d,
0x00006628, 0x00006687, 0x00006776, 0x000067d9, 0x00006494, 0x0000643b, 0x000065ca, 0x00006565
- ]
+ ].freeze
+ #
+ # Updates the CRC32 XFER checksum.
+ #
+ # @param [String] data
+ # The data to update the checksum with.
+ #
def update(data)
data.each_byte do |b|
@crc = (@table[((@crc >> 24) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffffff
end