class Digest::CRC15

Implements the CRC15 algorithm.

@since 0.5.0

Constants

TABLE

Generated by `./pycrc.py –algorithm=table-driven –model=crc-16 –generate=c`

WIDTH

Public Class Methods

pack(crc) click to toggle source

Packs the CRC15 checksum.

@param [Integer] crc

The CRC15 checksum to pack.

@return [String]

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

  buffer << ((crc & 0x7f00) >> 8).chr
  buffer << (crc & 0xff).chr

  buffer
end

Public Instance Methods

update(data) click to toggle source

Updates the CRC15 checksum.

@param [String] data

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

  return self
end