2017 © Pedro Peláez
 

library base85

Base85 encoder and decoder for arbitrary data

image

tuupola/base85

Base85 encoder and decoder for arbitrary data

  • Friday, April 13, 2018
  • by tuupola
  • Repository
  • 1 Watchers
  • 12 Stars
  • 4,496 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 12 % Grown

The README.md

All your Base85

Latest Version Software License Build StatusCoverage, (*1)

Install

Install with composer., (*2)

``` bash $ composer require tuupola/base85, (*3)


This branch requires PHP 7.1 or up. The older 1.x branch supports also PHP 5.6 and 7.0. ``` bash $ composer require "tuupola/base85:^1.0"

Usage

This package has both pure PHP and GMP 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., (*4)

``` php $base85 = new Tuupola\Base85;, (*5)

$encoded = $base85->encode(random_bytes(128)); $decoded = $base85->decode($encoded);, (*6)


If you are encoding to and from integer use the implicit `decodeInteger()` and `encodeInteger()` methods. ``` php $integer = $base85->encodeInteger(987654321); /* 3o4PT */ print $base85->decodeInteger("3o4PT", true); /* 987654321 */

Note that encoding a string and an integer will yield different results., (*7)

``` php $string = $base85->encode("987654321"); /* 3B/rU2)IE0` */ $integer = $base85->encodeInteger(987654321); / 3o4PT */, (*8)


## Encoding modes [ASCII85](https://en.wikipedia.org/wiki/Ascii85) encoding. This is the default. `0x00000000` is compressed to `z`. Spaces are not compressed. ``` php use Tuupola\Base85; $ascii85 = new Base85([ "characters" => Base85::ASCII85, "compress.spaces" => false, "compress.zeroes" => true ]); print $ascii85->encode("Hello world!"); /* 87cURD]j7BEbo80 */

Adobe ASCII85 encoding is same as previous except data is enclosed between <~ and ~>., (*9)

``` php use Tuupola\Base85;, (*10)

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

print $adobe85->encode("Hello world!"); /* ~87cURD]j7BEbo80~ */, (*12)


[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. ``` php use Tuupola\Base85; $z85 = new Base85([ "characters" => Base85::Z85, "compress.spaces" => false, "compress.zeroes" => false ]); print $z85->encode("Hello world!"); /* NM=qnZy<MXa+]NF */

Character set from RFC1924 which is an April fools joke. Spaces and zeroes are not compressed., (*13)

``` php use Tuupola\Base85;, (*14)

$rfc1924 = new Base85([ "characters" => Base85::RFC1924, "compress.spaces" => false, "compress.zeroes" => false ]);, (*15)

print $rfc1924->encode("Hello world!"); /* NM&qnZy<MXa%^NF */, (*16)


## Speed Pure PHP encoder seems to be faster than the GMP implementation. Below benchmarks use `random_bytes(128)` as data.

$ php --version PHP 8.0.1 (cli) (built: Jan 8 2021 09:07:02) ( NTS ), (*17)

$ vendor/bin/phpbench run benchmarks/ --report=default, (*18)

+-----------------+-----------------+-------+ | subject | mean | diff | +-----------------+-----------------+-------+ | benchGmpDecoder | 24,515.692ops/s | 1.01x | | benchPhpDecoder | 24,666.509ops/s | 1.00x | +-----------------+-----------------+-------+ +-----------------+-----------------+-------+ | subject | mean | diff | +-----------------+-----------------+-------+ | benchGmpEncoder | 9,654.448ops/s | 4.76x | | benchPhpEncoder | 45,944.903ops/s | 1.00x | +-----------------+-----------------+-------+, (*19)


## Static Proxy If you prefer static syntax use the provided static proxy. ```php use Tuupola\Base85Proxy as Base85; print Base85::encode("Hello world!") /* 87cURD]j7BEbo80 */

To change static proxy options set the Base85::$options variable., (*20)

use Tuupola\Base85;
use Tuupola\Base85Proxy as Z85;

Z85::$options = [
    "characters" => Base85::Z85,
    "compress.spaces" => false,
    "compress.zeroes" => false
];

print Z85::encode("Hello world!"); /* NM=qnZy<MXa+]NF */

Testing

You can run tests either manually or automatically on every code change. Automatic tests require entr to work., (*21)

``` bash $ make test, (*22)

``` bash
$ brew install entr
$ make watch

Contributing

Please see CONTRIBUTING for details., (*23)

Security

If you discover any security related issues, please email tuupola@appelsiini.net instead of using the issue tracker., (*24)

License

The MIT License (MIT). Please see License File for more information., (*25)

The Versions

13/04 2018
01/04 2017

0.3.1

0.3.1.0 https://github.com/tuupola/base85

Base85 encoder and decoder for arbitrary data

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

base85

10/03 2017

0.3.0

0.3.0.0 https://github.com/tuupola/base85

Base85 encoder and decoder for arbitrary data

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

base85

26/02 2017

0.2.0

0.2.0.0 https://github.com/tuupola/base85

Base85 encoder and decoder for arbitrary data

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

base85

20/02 2017

0.1.0

0.1.0.0 https://github.com/tuupola/base85

Base85 encoder and decoder for arbitrary data

  Sources   Download

MIT

The Requires

  • php ^5.5 || ^7.0

 

The Development Requires

base85