mermshaus / crc
Calculates CRC checksums for input data.
v1.0.0
2026-08-25 07:44 UTC
Requires
- php: >=8.2
Requires (Dev)
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
I’m not an expert on the topic by any means. Therefore, I have trouble finding and verifying information about common CRC algorithms.
Implemented algorithms
Alias names in parentheses.
- CRC-1 [1]
- CRC-16 [2]
- CRC-16/IBM-3740 (CRC-16/CCITT-FALSE)
- CRC-16/DNP
- CRC-16/MODBUS
- CRC-16/IBM-SDLC (CRC16-QT [3])
- CRC-16/USB
- CRC-16/XMODEM (CRC-16/ZMODEM)
1: Might be a misnomer inherited from the algorithm list this library was built against.
2: Most likely CRC-16/ARC.
3: This was also part of the original library. It doesn’t seem to be a catalogue alias. That’s why it’s not formatted as one.
Usage example
<?php // Autoloading via Composer require __DIR__ . '/vendor/autoload.php'; $crc = new \mermshaus\CRC\CRC16IBM3740(); $crc->update('Hello'); $crc->update(' World!'); $checksum = $crc->finish(); var_dump(bin2hex($checksum)); // string(4) "882a"
Testing
Note: The current test setup tries to use the PHP version installed on the system (php command). If none is found, it will try to build a Docker container based on php-cli and use that.
$ make test
Credits
- This library is mostly a port of Digest CRC for Ruby by Hal Brodigan.
Links
- Digest CRC. The Ruby library on which this library is based.
- pycrc. A tool for generating C code and corresponding lookup tables for diverse CRC algorithms. Used by Digest CRC.
- CRC calculation. An online calculator to generate checksums for arbitrary polynomials and input. Recommended by pycrc.
- On-line CRC calculation and free library. Another online calculator for some CRC algorithms.
- Catalogue of parametrised CRC algorithms. Information about many different CRC algorithms.