S
S
Sergey Pugovkin2018-04-10 20:02:22
PHP
Sergey Pugovkin, 2018-04-10 20:02:22

How to change the number system from 0-f to 0-zZ?

Tell me the algorithm for converting md5-hash from 12a0aef... (or directly from binary raw) to d1t5Zxs...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Pugovkin, 2018-04-10
@Driver86

function baseConvert(string $number, int $fromBase, int $toBase) {
    $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_';
    if ($fromBase == 10) {
        $int = $number;
    } else {
        $int = 0;
        $len = strlen($number);
        $numberRev = strrev($number);
        for ($i = 0; $i < $len; $i++) {
            $int = gmp_add($int, gmp_mul($chars[strpos($chars, $numberRev[$i])], gmp_pow($fromBase, $i)));
        }
    }
    $converted = '';
    while (gmp_cmp($int, 0) > 0) {
        list ($int, $remainder) = gmp_div_qr($int, $toBase);
        $converted = $chars[gmp_intval($remainder)] . $converted;
    }
    return $converted;
}

M
Mercury13, 2018-04-10
@Mercury13

Most likely some variant of BASE64.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question