Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xobotyi/basen
Text encoding utilities for PHP with no extensions dependencies. Base32, Base58, Base64 and much more!
https://github.com/xobotyi/basen
base16 base32 base36 base58 base62 base64 binary encoding php7 rfc4648 text
Last synced: 6 days ago
JSON representation
Text encoding utilities for PHP with no extensions dependencies. Base32, Base58, Base64 and much more!
- Host: GitHub
- URL: https://github.com/xobotyi/basen
- Owner: xobotyi
- License: mit
- Created: 2018-06-06T07:29:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-21T15:32:56.000Z (over 4 years ago)
- Last Synced: 2024-09-19T19:50:20.857Z (about 2 months ago)
- Topics: base16, base32, base36, base58, base62, base64, binary, encoding, php7, rfc4648, text
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
BaseN
## About
PHP is a great language but unfortunately provides us with only one text encoding (base64) which even not URL safe. And there are no straight way to change its alphabet.
BaseN solves that problem and implements common binary-to-text algorithm for encodings whose alphabet fully covers number of bits that corresponds its length. And rough algorithm which will encode each byte separately, it is less compact but guarantee the encoding with given alphabet.
Furthermore it gives you methods to encode and decode integers themselves instead of their text representation.## Requirements
- [PHP](//php.net/) 7.1+## Installation
Install with composer
```bash
composer require xobotyi/basen
```## Usage
```php
use xobotyi\basen\BaseN;
use xobotyi\basen\Base58;// use it for something usual
$base8 = new BaseN('01234567', false, false, false);
echo $base8->encode(16) . "\n"; // 142330
echo $base8->encodeInt(16) . "\n"; // 20// or create your own encoder with own alphabet if needed
$myOwnEncoder = new BaseN('a123d8e4fiwnmqkl', false, true, true);
echo $myOwnEncoder->encode(16) . "\n"; // 313e
echo $myOwnEncoder->encodeInt(16) . "\n"; // 1a// predefined encoder
echo Base58::encode(16) . "\n"; // 3hC
// or, with alternative alphabet
echo Base58::encode(16, Base58::ALPHABET_RIPPLE) . "\n"; // hkD
echo Base58::encodeInt(16) . "\n"; // G
```## Builtin encodings
BaseN provides few classes implementing most popular encodings:
- [Base16](https://en.wikipedia.org/wiki/Base16) (0-9a-f)
- [Base32](https://en.wikipedia.org/wiki/Base32) (a-z2-7)
- [Base36](https://en.wikipedia.org/wiki/Base36) (0-9a-z)
- [Base58](https://en.wikipedia.org/wiki/Base58) (0-9A-Za-v)
- Base62 (0-9A-Za-z)
- [Base64](https://en.wikipedia.org/wiki/Base64) (0-9A-Za-z+/)
- [Base85](https://en.wikipedia.org/wiki/Base85) (!"#$%&'()*+,-./0-9:;<=>?@A-Z[\]^_`a-u)