2017 © Pedro Peláez
 

library baseconvert

Convertation from/to any user-defined base-chars-string throught decimal representation of arbitrary precision

image

ierusalim/baseconvert

Convertation from/to any user-defined base-chars-string throught decimal representation of arbitrary precision

  • Monday, February 26, 2018
  • by ierusalim
  • Repository
  • 1 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

BaseConvert

Build Status, (*1)

Convertation from/to any user-defined base-chars-string throught decimal representation of arbitrary precision., (*2)

Installation

File BaseConvert.php may be use independent., (*3)

For composer:, (*4)

composer require ierusalim/baseconvert
````

## Usage BaseConvert


Create instance of BaseConvert class and define own base-characters string (if need).

No need to define new alphabet for use hex/binary/base58(bitcoin compatible).

```php
use ierusalim\BaseConvert;

$bc = new BaseConvert;

$hex = "43786437856abcdef";
$b58 = $bc->hextobase58($hex);

echo "$hex => base58: $b58";

Functions

  • -> dectohex($dec) -- Convert from decimal (012345679-base) to hex (0123456789abcdef-base)
  • -> hextodec($hex) -- Convert from hex (0123456789abcdef-base) to decimal (012345679-base)
  • -> dectobits($dec) -- Convert from decimal (012345679-base) to string of bits (01-base)
  • -> bitstodec($bits) -- Convert from bits to decimal representation of arbitrary precision
  • -> hextobits($hex) -- Convert from hex (0123456789abcdef-base) to bits string (01-base)
  • -> bitstohex($bits) -- Convert from bits (01-base) to hex (0123456789abcdef-base)
  • -> dectobase58($dec) -- Convert from decimal (012345679-base) to base58
  • -> hextobase58($hex) -- Convert from hex (0123456789abcdef-base) to base58
  • -> base58tohex($b58) -- Convert from base58 to hex (0123456789abcdef-base)
  • -> basex_decode($data, $base_id) -- Convert from arbitrary base to decimal
  • -> basex_encode($dec, $base_id) -- Convert from decimal to arbitrary base

Usage vc85

vc85 is a one of many base85-algorithms, like ascii85, z85, etc., (*5)

Encoding vc85 has the following features: - Each character is visually unique and easily recognizable: 0123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyzзгджилпфцчшюяБГДЖИЛПФЦЧШЮЯ - Encoded result does not contain special characters; - encoding and decoding runs fast., (*6)

use ierusalim\BaseConvert;

$bc = new vc85();

$str = "One day I'm gonna fly away One day when heavens calls my name";
$enc = $bc->vc85_encode($str);

echo "result: $enc \n";

// result: RkШжцYNQлAPjhWЮZLжz9XJZEЯeФ3nVXTБЮДbgГЧ3XTБЯVZnЯ67ZnЮtЦYrЯpJXФШGБd0BUdAbЮu81G

$back = $bc->vc85_decode($enc);

echo ($str === $back) ? "OK" : "Fail";

Functions vc85

  • -> vc85_encode($str) -- Convert from binary data to vc85
  • -> vc85_decode($str) -- Convert from vc85 to binary data

Functions base6400

  • -> base6400_encode($str) -- Convert from binary to base6400
  • -> base6400_decode($str) -- Convert from base6400 to binary
  • -> explodeToUnicode($str) -- Convert string from utf-8 to Unicode-array
  • -> implodeUnicode($arr) -- Convert Unicode-array to utf-8 string

Bases (pre-defined base_id)

    public $bases = [
        2 => '01',
        3 => '012',
        4 => '0123',
        8 => '01234567',
        10 => '0123456789',
        16 => '0123456789abcdef',
        58 => '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
    ];

The Versions

26/02 2018

dev-master

9999999-dev

Convertation from/to any user-defined base-chars-string throught decimal representation of arbitrary precision

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3
  • ext-bcmath *

 

The Development Requires

by Alexander Jer

bitcoin base58 baseconvert dectohex hextodec dechex hexdec dectobin dectobits bitstodec

17/02 2018

0.1.0

0.1.0.0

Convertation from/to any user-defined base-chars-string throught decimal representation of arbitrary precision

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3
  • ext-bcmath *

 

The Development Requires

by Alexander Jer

bitcoin base58 baseconvert dectohex hextodec dechex hexdec dectobin dectobits bitstodec