如何使用 PHP 计算与某个行键对应的 Cassandra 令牌
“他们”说这是 MD5,以十进制转换,但是我正在计算的,似乎不是正确的标记。
//this is one of the ways i tried,
number_format(hexdec( md5($key ) ), 0, '', '')
//this is second:
md5_hex_to_dec( md5($key) );
function md5_hex_to_dec($hex_str)
{
// here i experimented with higher bit.
$c = $hex_str[0];
$c1 = hexdec($c);
if ($c1 > 7)
$c1 = $c1 - 7;
// --- eo ----
$hex_str[0] = dechex($c1);
$arr = str_split($hex_str, 4);
foreach ($arr as $grp) {
$dec[] = str_pad(hexdec($grp), 5, '0', STR_PAD_LEFT);
}
return implode('', $dec);
}