Skip to content

Turning into a number integer from checksum state in PHP

Dr. Simon Antony Roberts edited this page Dec 4, 2019 · 2 revisions

The following PHP will convert with the function 'convertXCP2Int('abvscge33exw')' an XCP Checksum to a integer/double representative number

<?php

if (!function_exists("bcmod")) {
    function bcmod( $x, $y )
    {
        $take = 5;    
        $mod = '';
        do
        {
            $a = (int)$mod.substr( $x, 0, $take );
            $x = substr( $x, $take );
            $mod = $a % $y;   
        }
        while ( strlen($x) );
        return (int)$mod;
    }
}

if (!function_exists("convertXCP2Int")) {
    function convertXCP2Int($xcp = '', $modulus = 1234567890) {
        return bcmod(base_convert($xcp, 64, 10), $modulus);
    }
}

?>