PHPackages                             codepower/anybase - 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. codepower/anybase

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

codepower/anybase
=================

Convert integers between arbitrary bases with custom alphabets, salt, padding, and big-integer support.

0.1.0(1mo ago)01.2k↑128.7%MITPHPPHP ^8.1CI passing

Since May 8Pushed 1w agoCompare

[ Source](https://github.com/codepower-tw/anybase-php)[ Packagist](https://packagist.org/packages/codepower/anybase)[ Docs](https://github.com/codepower-tw/anybase-php)[ RSS](/packages/codepower-anybase/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

anybase-php
===========

[](#anybase-php)

Convert non-negative integers (including DB-primary-key big integers) between arbitrary numeric bases using custom alphabets. For URL-friendly ID obfuscation, short codes, and human-readable hashing — **not** for cryptographic security.

Install
-------

[](#install)

```
composer require codepower/anybase

```

PHP 8.1+. Optional: `ext-gmp` (preferred) or `ext-bcmath` for integers larger than `PHP_INT_MAX`.

Quick start
-----------

[](#quick-start)

```
use Anybase\Codec;
use Anybase\Alphabets;

$codec = Codec::for(Alphabets::base62());
$codec->encode(123456789);   // "8M0kX"
$codec->decode("8M0kX");     // "123456789"
```

Custom alphabet
---------------

[](#custom-alphabet)

```
use Anybase\Alphabet;

$codec = Codec::for(Alphabet::fromString('0289PYLQGRJCUV'));
$codec->encode(98765); // "8QVUR"
```

Salt (per-environment scrambling)
---------------------------------

[](#salt-per-environment-scrambling)

XOR the integer with a fixed salt so that staging IDs and prod IDs don't visually overlap. **This is not encryption** — anyone with one plaintext- ciphertext pair can recover the salt.

```
$codec = Codec::for(Alphabets::crockfordBase32())->withSalt(0xDEADBEEF);
```

Padding
-------

[](#padding)

```
$codec = Codec::for(Alphabets::base62())->withMinLength(8);
$codec->encode(42);   // "0000000g"
```

Convert between bases
---------------------

[](#convert-between-bases)

```
use Anybase\BaseConverter;

$conv = new BaseConverter(Alphabets::base16(), Alphabets::base62());
$conv->convert('deadbeef');
```

Predefined alphabets
--------------------

[](#predefined-alphabets)

`base2` `base8` `base10` `base16` `base16Upper` `base32Rfc4648` `base32Hex``crockfordBase32` `base36` `base58Bitcoin` `base58Flickr` `base62``base64Url` `supercellHashtag`

Crockford base32 folds `I/L → 1` and `O → 0` on decode and is case-insensitive.

Supercell hashtag folds `I/1 → L`, `O → 0`, `B → 8` on decode and is case-insensitive by default. Both behaviors are configurable:

```
Alphabets::supercellHashtag();                 // default foldings + case-insensitive
Alphabets::supercellHashtag([]);               // no foldings, still case-insensitive
Alphabets::supercellHashtag(['Z' => '2']);     // custom fold map
Alphabets::supercellHashtag([], caseInsensitive: false); // strict
```

Big integers
------------

[](#big-integers)

For values larger than `PHP_INT_MAX` (2^63 − 1), install `ext-gmp` (preferred) or `ext-bcmath`. The library auto-selects:

1. Native PHP int when the value fits.
2. GMP when available.
3. BCMath as fallback.

Pin a specific backend with `->withBackend(new \Anybase\Backend\NativeBackend())`.

Errors
------

[](#errors)

All exceptions implement `\Anybase\Exception\AnybaseException`. Specific classes: `InvalidAlphabetException`, `InvalidInputException`, `OverflowException`, `MissingExtensionException`.

Testing
-------

[](#testing)

This package uses Pest 2:

```
composer test

```

License
-------

[](#license)

MIT.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance96

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

32d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/45706aa5bfc19f315d6f7d424d0cf95fc8b13a3076d827f84577a45470d83ee4?d=identicon)[gasol](/maintainers/gasol)

---

Top Contributors

[![Gasol](https://avatars.githubusercontent.com/u/108053?v=4)](https://github.com/Gasol "Gasol (33 commits)")

---

Tags

base64encodedecodehashidsbase32base16base62obfuscationid obfuscationbase58crockfordbase converterbase36base\_convert

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/codepower-anybase/health.svg)

```
[![Health](https://phpackages.com/badges/codepower-anybase/health.svg)](https://phpackages.com/packages/codepower-anybase)
```

###  Alternatives

[hashids/hashids

Generate short, unique, non-sequential ids (like YouTube and Bitly) from numbers

5.5k50.9M302](/packages/hashids-hashids)[paragonie/constant_time_encoding

Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)

904351.6M178](/packages/paragonie-constant-time-encoding)[jenssegers/optimus

Id obfuscation based on Knuth's integer hash method

1.3k4.9M32](/packages/jenssegers-optimus)[christian-riesen/base32

Base32 encoder/decoder according to RFC 4648

13433.2M69](/packages/christian-riesen-base32)[sqids/sqids

Generate short YouTube-looking IDs from numbers

6041.6M42](/packages/sqids-sqids)[xobotyi/basen

Text and integers encoding utilities for PHP with no extensions dependencies. Base32, Base58, Base64 and much more!

1220.1k](/packages/xobotyi-basen)

PHPackages © 2026

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