Class Crc

extends Checksum

Class summary


little-endian width/int --polynomial/int --initial-state/int= --xor-result/int= -> Crc
Construct a CRC that processes bits in little-endian-first order.
little-endian width/int --normal-polynomial/int --initial-state/int= --xor-result/int= -> Crc
Construct a CRC that processes bits in little-endian-first order.
little-endian width/int --powers/List --initial-state/int= --xor-result/int= -> Crc
Construct a CRC that processes bits in little-endian-first order.
big-endian width/int --polynomial/int --initial-state/int= --xor-result/int= -> Crc
Construct a CRC that processes bits in big-endian-first order.
big-endian width/int --powers/List --initial-state/int= --xor-result/int= -> Crc
Construct a CRC that processes bits in big-endian-first order.

Statics

big-endian width/int --polynomial/int --initial-state/int=0 --xor-result/int=0 -> Crc
Construct a CRC that processes bits in big-endian-first order.
The polynomial is an integer encoding of width width with the most significant bit representing the x^0 term, and the least significant bit representing the x^width-1 term.
The width must be in the range of 8-64 bits.
Example

// The CRC-16 used in Xmodem.
crc := Crc.big-endian 16 --polynomial=0x1021

big-endian width/int --powers/List --initial-state/int=0 --xor-result/int=0 -> Crc
Construct a CRC that processes bits in big-endian-first order.
The powers are a list of the powers in the representation of the CRC polynormial.
The power corresponding to the width (32 for the x³² term in CRC-32) can be omitted since it is implied by the width of the CRC.
The width must be in the range of 8-64 bits.
Example

// The popular CRC-16 used in Xmodem.
crc := Crc.big-endian 16 --powers=[12, 5, 0]
// Equivalently:
crc := Crc.big-endian 16 --powers=[16, 12, 5, 0]

little-endian width/int --polynomial/int --initial-state/int=0 --xor-result/int=0 -> Crc
Construct a CRC that processes bits in little-endian-first order.
The polynomial is an integer encoding of width width with the most significant bit representing the x^0 term, and the least significant bit representing the x^width-1 term. This is the little endian (reversed) ordering for the polynomial.
The width must be in the range of 3-64 bits.
Example

// The CRC-32 used in PNG.
crc := Crc.little-endian 32 --polynomial=0xEDB88320 --initial-state=0xffff_ffff --xor-result=0xffff_ffff

little-endian width/int --normal-polynomial/int --initial-state/int=0 --xor-result/int=0 -> Crc
Construct a CRC that processes bits in little-endian-first order.
The normal-polynomial is an integer encoding of width width with the least significant bit representing the x^0 term, and the most significant bit representing the x^width-1 term. This is the normal ordering for the polynomial.
The width must be in the range of 3-64 bits.
Example

// The CRC-32 used in PNG.
crc := Crc.little-endian 32 --normal-polynomial=0x04C11DB7 --initial-state=0xffff_ffff --xor-result=0xffff_ffff

little-endian width/int --powers/List --initial-state/int=0 --xor-result/int=0 -> Crc
Construct a CRC that processes bits in little-endian-first order.
The powers are a list of the powers in the representation of the CRC polynormial.
The power corresponding to the width (32 for the x³² term in CRC-32) can be omitted since it is implied by the width of the CRC.
The width must be in the range of 3-64 bits.
Example

// The CRC-32 used in PNG.
// x³² + x²⁶ + x²³ + x²² + x¹⁶ + x¹² + x¹¹ + x¹⁰ + x⁸ + x⁷ + x⁵ + x⁴ + x² + x + 1.
crc := Crc.little-endian 32
    --powers=[26, 23, 22, 16, 12, 11, 10, 8, 7, 5, 4, 2, 1, 0]
    --initial-state=0xffff_ffff
    --xor-result=0xffff_ffff
// Equivalently:
crc := Crc.little-endian 32
    --powers=[32, 26, 23, 22, 16, 12, 11, 10, 8, 7, 5, 4, 2, 1, 0]
    --initial-state=0xffff_ffff
    --xor-result=0xffff_ffff

Methods

add data/Data from/int to/int -> none
See super.

add data/Data -> none
Variant of add data from to.

add data/Data from/int -> none
Variant of add data from to.

See super.
Returns the checksum as a width/8 element byte array in the endian order that corresponds to the constructor used.

Returns the checksum as an integer.

operator == other/any -> bool

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.