承接 codepower/anybase 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codepower/anybase

Composer 安装命令:

composer require codepower/anybase

包简介

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

README 文档

README

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

composer require codepower/anybase

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

Quick start

use Anybase\Codec;
use Anybase\Alphabets;

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

Custom alphabet

use Anybase\Alphabet;

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

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

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

Convert between bases

use Anybase\BaseConverter;

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

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

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

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

Testing

This package uses Pest 2:

composer test

License

MIT.

统计信息

  • 总下载量: 3.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固