PHP code example of ocubom / base-convert

1. Go to this page and download the library: Download ocubom/base-convert library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ocubom / base-convert example snippets


    use function Ocubom\Math\base_convert;
  
    $hex = base_convert(random_bytes(32), 'bin', 'hex');
    

    use Ocubom\Math\Base\Crockford;
    use function Ocubom\Math\base_convert;
  
    // Encoding
    $crockford = base_convert(random_bytes(32), 'bin', new Crockford());

    // Decoding
    $hex = base_convert($crockford, new Crockford(), 'hex');
    

    use Ocubom\Math\Crockford;
  
    // Encoding
    $crockford = Crockford::encode(random_bytes(32), 'bin');

    // Decoding
    $hex = Crockford::decode($crockford, 'hex');
    

    use function Ocubom\Math\crockford_decode;
    use function Ocubom\Math\crockford_encode;
  
    // Encoding
    $crockford = crockford_encode(random_bytes(32), 'bin');

    // Decoding
    $hex = crockford_decode($crockford, 'hex');
    

use Ocubom\Math\Base\Base58Btc;
use Ocubom\Math\Base\Base58Flickr;
use Ocubom\Math\Base\Base58Xrp;
use function Ocubom\Math\base_convert;

$bytes = random_bytes(32);

// Encoding with different alphabets
$btc    = base_convert($bytes, 'bin', new Base58Btc());
$flickr = base_convert($bytes, 'bin', new Base58Flickr());
$xrp    = base_convert($bytes, 'bin', new Base58Xrp());

// Decoding
$hex = base_convert($btc, new Base58Btc(), 'hex');