I have a Base32 info hash. e.g. IXE2K3JMCPUZWTW3YQZZOIB5XD6KZIEQ
, and I need to convert it to base16.
How can I do it with PHP?
My code looks like this:
$hash32=strtolower($hash32);
echo $hash32; // shows - IXE2K3JMCPUZWTW3YQZZOIB5XD6KZIEQ
$hash32=sha1($hash32);
$hash16=base_convert($hash32, 32, 16);
echo "</br>";
echo $hash16 // shows - 3ee5e7325a282c56fe2011125e0492f6ffbcd467
In my code the 16 based info hash is not valid..
The valid Info hash is 45C9A56D2C13E99B4EDBC43397203DB8FCACA090
How can I get a valid info hash?
Thanks
I give you an answer with voluntarily omitting
gmp_strval(gmp_init(strtoupper($hash32), 32), 16);
which only works with GMP installed in your server.This function, found here, "converts an arbitrarily large number from any base to any base". You only need to convert from base 32 to base 16, hence:
base 32 alphabet is:
ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
The problem here was that
base_convert
mishandle large numbers.