PHPackages                             tuupola/base85 - 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. tuupola/base85

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

tuupola/base85
==============

Base85 encoder and decoder for arbitrary data

2.1.1(4mo ago)30193.2k—1.8%2[2 issues](https://github.com/tuupola/base85/issues)1MITPHPPHP ^7.1|^8.0CI failing

Since Feb 20Pushed 4mo ago2 watchersCompare

[ Source](https://github.com/tuupola/base85)[ Packagist](https://packagist.org/packages/tuupola/base85)[ Docs](https://github.com/tuupola/base85)[ RSS](/packages/tuupola-base85/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelogDependencies (6)Versions (12)Used By (1)

All your Base85
===============

[](#all-your-base85)

[![Latest Version](https://camo.githubusercontent.com/b38ac57118864da15f270fb9aca053f8d5d51e110280de137dbb9f397c7089b2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f747575706f6c612f6261736538352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tuupola/base85)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/669289b24767ae2e0eab111297557c583d9a8fdc3cdb7aeb079cd25adb555a4c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f747575706f6c612f6261736538352f74657374732e796d6c3f6272616e63683d322e78267374796c653d666c61742d737175617265)](https://github.com/tuupola/base85/actions)[![Coverage](https://camo.githubusercontent.com/5b3600fb9a0ad518a5969e7fe7afeecdefeb140e941f086ac0fdcb24dd4f4698/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f747575706f6c612f6261736538352e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/tuupola/base85)

Install
-------

[](#install)

Install with [composer](https://getcomposer.org/).

```
$ composer require tuupola/base85
```

This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0.

```
$ composer require "tuupola/base85:^1.0"
```

Usage
-----

[](#usage)

This package has both pure PHP and [GMP](http://php.net/manual/en/ref.gmp.php) based encoders. By default encoder and decoder will use GMP functions if the extension is installed. If GMP is not available pure PHP encoder will be used instead.

```
$base85 = new Tuupola\Base85;

$encoded = $base85->encode(random_bytes(128));
$decoded = $base85->decode($encoded);
```

If you are encoding to and from integer use the implicit `decodeInteger()` and `encodeInteger()` methods.

```
$integer = $base85->encodeInteger(987654321); /* 3o4PT */
print $base85->decodeInteger("3o4PT", true); /* 987654321 */
```

Note that encoding a string and an integer will yield different results.

```
$string = $base85->encode("987654321"); /* 3B/rU2)I*E0` */
$integer = $base85->encodeInteger(987654321); /* 3o4PT */
```

Encoding modes
--------------

[](#encoding-modes)

[ASCII85](https://en.wikipedia.org/wiki/Ascii85) encoding. This is the default. `0x00000000` is compressed to `z`. Spaces are not compressed.

```
use Tuupola\Base85;

$ascii85 = new Base85([
    "characters" => Base85::ASCII85,
    "compress.spaces" => false,
    "compress.zeroes" => true
]);

print $ascii85->encode("Hello world!"); /* 87cURD]j7BEbo80 */
```

[Adobe ASCII85](https://en.wikipedia.org/wiki/Ascii85) encoding is same as previous except data is enclosed between ``.

```
use Tuupola\Base85;

$adobe85 = new Base85([
    "characters" => Base85::ASCII85,
    "compress.spaces" => false,
    "compress.zeroes" => true,
    "prefix" => ""
]);

print $adobe85->encode("Hello world!"); /*  */
```

[ZeroMQ (Z85)](https://rfc.zeromq.org/spec:32/Z85/) encoding. NOTE! Even though specification says input length must be divisible by 4, this is not currently enforced. Spaces and zeroes are not compressed.

```
use Tuupola\Base85;

$z85 = new Base85([
    "characters" => Base85::Z85,
    "compress.spaces" => false,
    "compress.zeroes" => false
]);

print $z85->encode("Hello world!"); /* NM=qnZy Base85::RFC1924,
    "compress.spaces" => false,
    "compress.zeroes" => false
]);

print $rfc1924->encode("Hello world!"); /* NM&qnZy Base85::Z85,
    "compress.spaces" => false,
    "compress.zeroes" => false
];

print Z85::encode("Hello world!"); /* NM=qnZy
