module Renoir::CRC16
This is the CRC16
algorithm used by Redis Cluster to hash keys. Implementation according to CCITT standards.
This is actually the XMODEM CRC 16 algorithm, using the following parameters:
-
Name : “XMODEM”, also known as “ZMODEM”, “CRC-16/ACORN”
-
Width : 16 bit
-
Poly : 1021 (That is actually x^16 + x^12 + x^5 + 1)
-
Initialization : 0000
-
Reflect Input byte : False
-
Reflect Output CRC : False
-
Xor constant to output CRC : 0000
-
Output for “123456789” : 31C3
Constants
- XMODEM_CRC16_LOOKUP
Public Class Methods
crc16(bytes)
click to toggle source
# File lib/renoir/crc16.rb, line 17 def self.crc16(bytes) crc = 0 bytes.each_byte do |b| crc = ((crc << 8) & 0xffff) ^ XMODEM_CRC16_LOOKUP[((crc >> 8) ^ b) & 0xff] end crc end