PHP code example of pleonasm / merkle-tree

1. Go to this page and download the library: Download pleonasm/merkle-tree 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/ */

    

pleonasm / merkle-tree example snippets



use Pleo\Merkle\FixedSizeTree;

merkle tree hashing does
$hasher = function ($data) {
    return hash('sha256', hash('sha256', $data, true), true);
};

$finished = function ($hash) {
    echo implode('', unpack('H*', $hash)) . "\n";
};

$tree = new FixedSizeTree(16, $hasher, $finished);

$tree->set(0, 'Science');
$tree->set(1, 'is');
$tree->set(2, 'made');
$tree->set(3, 'up');
$tree->set(4, 'of');
$tree->set(5, 'so');
$tree->set(6, 'many');
$tree->set(7, 'things');
$tree->set(8, 'that');
$tree->set(9, 'appear');
$tree->set(10, 'obvious');
$tree->set(11, 'after');
$tree->set(12, 'they');
$tree->set(13, 'are');
$tree->set(14, 'explained');
$tree->set(15, '.'); // this will echo the string 'c689102cdf2a5b30c2e21fdad85e4bb401085227aff672a7240ceb3410ff1fb6'