PHPackages                             bafs/crc-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bafs/crc-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bafs/crc-php
============

v0.3.1(1y ago)411.4k↓17.1%1MITPHPPHP &gt;=8.1CI passing

Since Apr 3Pushed 12mo ago1 watchersCompare

[ Source](https://github.com/BafS/crc-php)[ Packagist](https://packagist.org/packages/bafs/crc-php)[ RSS](/packages/bafs-crc-php/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

CRC-PHP
=======

[](#crc-php)

Flexible implementation of cyclic redundancy check (CRC) in PHP 8.1+.

Install
-------

[](#install)

```
composer require bafs/crc-php

```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Example using CRC24/OPENPGP

```
$encoder = CrcFactory::create(CrcType::CRC24_OPENPGP);
echo dechex($encoder->compute('test')); // f86ed0
```

### Recommended Usage (using memoization)

[](#recommended-usage-using-memoization)

It 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).

You can generate the table with `Encoder::generateTable()`.

```
$encoder = CrcFactory::create(CrcType::CRC24_OPENPGP);

print_r($encoder->generateTable()); // [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, ...]
```

You can see an example with a nicer output in `examples/generate-table.php`.

You should set this table during the bootstrapping of your application and/or in the service container.

```
// Bootstrap
$table = [0x0, 0x864cfb, 0x8ad50d, 0xc99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17, 0xa18139, ...];
$encoder = CrcFactory::create(CrcType::CRC24_OPENPGP, $table);

// Encoder will use the table to compute the hash
echo dechex($encoder->compute('test')); // f86ed0
```

### Advance Usage with Custom Parameters

[](#advance-usage-with-custom-parameters)

It is possible to give custom parameters to the encoder to get any CRC.

```
$encoder = CrcFactory::create(new Parameters(width: 8, poly: 0x07, init: 0x00));
echo dechex($encoder->compute('test')); // b9
```

You can also create parameters from a string.

```
$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
```

Tests
-----

[](#tests)

- Unit tests: `./vendor/bin/phpunit --testdox --color tests`
- Code quality: `./vendor/bin/psalm`

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance50

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 71.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~395 days

Total

4

Last Release

367d ago

PHP version history (2 changes)v0.1.0PHP &gt;=8.0

v0.3.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/837170204c2dc6beffb28cfca8ff9036709ac38d5f5f16ab2b8b8a7cb025c089?d=identicon)[BafS](/maintainers/BafS)

---

Top Contributors

[![BafS](https://avatars.githubusercontent.com/u/588205?v=4)](https://github.com/BafS "BafS (10 commits)")[![simonschaufi](https://avatars.githubusercontent.com/u/941794?v=4)](https://github.com/simonschaufi "simonschaufi (4 commits)")

---

Tags

crccrc16crc24crc32librarymemoizationphp

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bafs-crc-php/health.svg)

```
[![Health](https://phpackages.com/badges/bafs-crc-php/health.svg)](https://phpackages.com/packages/bafs-crc-php)
```

###  Alternatives

[voku/stringy

A string manipulation library with multibyte support

1863.9M26](/packages/voku-stringy)[mageplaza/magento-2-blog-extension

Magento 2 Blog extension

122748.9k5](/packages/mageplaza-magento-2-blog-extension)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

98148.0k3](/packages/nickurt-laravel-akismet)[wehaa/liveupdate

A Laravel Nova field.

29185.8k](/packages/wehaa-liveupdate)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
