About
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., (*1)
Base32Hex library
, (*2)
Base32Hex class implements base32hex algorithm (as stated in RFC 2938) and implements these two main static methods:
* Koksosk\Base32Hex::encode($string)
* Koksosk\Base32Hex::decode($string), (*3)
Also these helper functions are included:
* Koksosk\Base32Hex::stringToBinary($string)
* Koksosk\Base32Hex::binaryToString($string), (*4)
See usage section below to see examples of usage.
See the docs/ folder for generated API documentation., (*5)
Important
Please don't CONFUSE base32hex with base32 encoding, which looks is similar but it is different standard., (*6)
Requirements
Koksosk\Base32Hex requires PHP 5.3+, that's all., (*7)
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:, (*8)
{
"require": {
"koksosk/base32hex": "*"
}
}
Usage examples
Encode
Encoding string to base32hex., (*9)
// Encoding string 'Hello' to base32hex string
$s = \Koksosk\Base32Hex::encode('Hello');
var_dump($s);
This produces the following output:, (*10)
string(8) "91IMOR3F"
Decode
Decoding string from base32hex string., (*11)
// Decoding string from base32hex string '91IMOR3F'
$s = \Koksosk\Base32Hex::decode('91IMOR3F');
var_dump($s);
This produces the following output:, (*12)
string(5) "Hello"
String to binary
Convert string to binary string, (*13)
// 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):, (*14)
string(40) "0100100001100101011011000110110001101111"
Binary to string
Convert binary string to string, (*15)
// Converting binary string "0100100001100101011011000110110001101111" to string
$s = \Koksosk\Base32Hex::binaryToString("0100100001100101011011000110110001101111");
var_dump($s);
This produces the following output:, (*16)
string(40) "Hello"
License
Copyright © 2014 Tomas Chvostek., (*17)
Licensed under the MIT License see here., (*18)