koksosk/base32hex

Base32Hex encoder/decoder

dev-master 2014-12-03 16:07 UTC

This package is not auto-updated.

Last update: 2024-04-23 02:05:54 UTC


README

Base32Hex is simple and easy to use class for base32hex encoding/decoding. Learn more about base32hex in this wiki section or in RFC 2938 standard document.

Base32Hex library

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Base32Hex class implements base32hex algorithm (as stated in RFC 2938) and implements these two main static methods:

Also these helper functions are included:

See usage section below to see examples of usage. See the docs/ folder for generated API documentation.

Important

Please don't CONFUSE base32hex with base32 encoding, which looks is similar but it is different standard.

Requirements

Koksosk\Base32Hex requires PHP 5.3+, that's all.

Installation

The preferred method of installation is via Packagist, as this provides the PSR-0 autoloader functionality. The following composer.json will download and install the latest version of the Koksosk\Base32Hex library into your project:

{
    "require": {
        "koksosk/base32hex": "*"
    }
}

Usage examples

Encode

Encoding string to base32hex.

// Encoding string 'Hello' to base32hex string
$s = \Koksosk\Base32Hex::encode('Hello');

var_dump($s);

This produces the following output:

string(8) "91IMOR3F"

Decode

Decoding string from base32hex string.

// Decoding string from base32hex string '91IMOR3F'
$s = \Koksosk\Base32Hex::decode('91IMOR3F');

var_dump($s);

This produces the following output:

string(5) "Hello"

String to binary

Convert string to binary string

// Converting string "Hello" to binary string
$s = \Koksosk\Base32Hex::stringToBinary("Hello");

var_dump($s);

This produces the following output (length = 40bits = strlen("Hello") * 8 bits = 5 * 8 bits):

string(40) "0100100001100101011011000110110001101111"

Binary to string

Convert binary string to string

// Converting binary string "0100100001100101011011000110110001101111" to string
$s = \Koksosk\Base32Hex::binaryToString("0100100001100101011011000110110001101111");

var_dump($s);

This produces the following output:

string(40) "Hello"

License

Copyright © 2014 Tomas Chvostek.

Licensed under the MIT License see here.