class Digest::CRC24

Implements the CRC24 algorithm.

Constants

INIT_CRC
TABLE

Generated by `./pycrc.py –algorithm=table-drive –model=crc24 –generate=c`

WIDTH

Public Class Methods

pack(crc) click to toggle source

Packs the CRC24 checksum.

@param [Integer] crc

The checksum to pack.

@return [String]

The packed checksum.
# File lib/digest/crc24.rb, line 58
def self.pack(crc)
  buffer = ''

  buffer << ((crc & 0xff0000) >> 16).chr
  buffer << ((crc & 0x00ff00) >> 8).chr
  buffer << (crc & 0x0000ff).chr

  buffer
end

Public Instance Methods

update(data) click to toggle source

Updates the CRC24 checksum.

@param [String] data

The data to update the checksum with.
# File lib/digest/crc24.rb, line 74
def update(data)
  data.each_byte do |b|
    @crc = ((@table[((@crc >> 16) ^ b) & 0xff] ^ (@crc << 8)) & 0xffffff)
  end

  return self
end