PHP code example of bafs / crc-php
1. Go to this page and download the library: Download bafs/crc-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bafs / crc-php example snippets
$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP);
echo dechex($encoder->compute('test')); // f86ed0
$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP);
print_r($encoder->generateTable()); // [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, ...]
// Bootstrap
$table = [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17, 0xa18139, ...];
$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP, $table);
// Encoder will use the table to compute the hash
echo dechex($encoder->compute('test')); // f86ed0
$encoder = CrcFactory::create(new Parameters(width: 8, poly: 0x07, init: 0x00));
echo dechex($encoder->compute('test')); // b9
$encoder = CrcFactory::create(Parameters::createFromString('width=8 poly=0x07 init=0x00 refin=false refout=false xorout=0x00 check=0xf4 residue=0x00 name="CRC-8/SMBUS"'));
echo dechex($encoder->compute('test')); // b9
composer