{"id":20249995,"url":"https://github.com/bafs/crc-php","last_synced_at":"2025-04-10T22:45:07.137Z","repository":{"id":42486622,"uuid":"477360157","full_name":"BafS/crc-php","owner":"BafS","description":"Generic CRC implementation in modern PHP (CRC16, CRC24, CRC32 and more)","archived":false,"fork":false,"pushed_at":"2022-08-14T10:44:01.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T22:44:59.551Z","etag":null,"topics":["crc","crc16","crc24","crc32","library","memoization","php"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/bafs/crc-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BafS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-03T14:06:19.000Z","updated_at":"2024-06-24T06:59:15.000Z","dependencies_parsed_at":"2022-08-21T10:20:36.664Z","dependency_job_id":null,"html_url":"https://github.com/BafS/crc-php","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BafS%2Fcrc-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BafS%2Fcrc-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BafS%2Fcrc-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BafS%2Fcrc-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BafS","download_url":"https://codeload.github.com/BafS/crc-php/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248312190,"owners_count":21082637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crc","crc16","crc24","crc32","library","memoization","php"],"created_at":"2024-11-14T09:56:32.388Z","updated_at":"2025-04-10T22:45:07.117Z","avatar_url":"https://github.com/BafS.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CRC-PHP\n\nFlexible implementation of cyclic redundancy check (CRC) in PHP 8.0+.\n\n## Install\n\n```\ncomposer require bafs/crc-php\n```\n\n## Usage\n\n### Basic Usage\n\nExample using CRC24/OPENPGP\n\n```php\n$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP);\necho dechex($encoder-\u003ecompute('test')); // f86ed0\n```\n\n### Recommended Usage (using memoization)\n\nIt is recommended to use [memoization](https://en.wikipedia.org/wiki/Memoization) to make the calculation faster (~10x, it varies from the input and the CRC used, see `examples/benchmark.php` for more details).\n\nYou can generate the table with `Encoder::generateTable()`.\n\n```php\n$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP);\n\nprint_r($encoder-\u003egenerateTable()); // [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, ...]\n```\n\nYou can see an example with a nicer output in `examples/generate-table.php`.\n\nYou should set this table during the bootstrapping of your application and/or in the service container.\n\n```php\n// Bootstrap\n$table = [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17, 0xa18139, ...];\n$encoder = CrcFactory::create(CrcFactory::CRC24_OPENPGP, $table);\n\n// Encoder will use the table to compute the hash\necho dechex($encoder-\u003ecompute('test')); // f86ed0\n```\n\n### Advance Usage with Custom Parameters\n\nIt is possible to give custom parameters to the encoder to get any CRC.\n\n```php\n$encoder = CrcFactory::create(new Parameters(width: 8, poly: 0x07, init: 0x00));\necho dechex($encoder-\u003ecompute('test')); // b9\n```\n\nYou can also create parameters from a string.\n\n```php\n$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\"'));\necho dechex($encoder-\u003ecompute('test')); // b9\n```\n\n## Tests\n\n- Unit tests: `./vendor/bin/phpunit --testdox --color tests`\n- Code quality: `./vendor/bin/psalm`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbafs%2Fcrc-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbafs%2Fcrc-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbafs%2Fcrc-php/lists"}