Jump to content

Hash convert function ?


Cineex

Recommended Posts

i'm write a function for it and i came across a error I never had befor:

 

function trackerHash($infoHash)
{

$return = '';
$split = chunk_split($infoHash,2);
$split = explode("\n",$split);

array_shift($split);
array_shift($split);
array_pop($split);
$i = 1;

foreach($split as $value)
{
	if($i == count($split)) $return .=  $value;
	else $return .=  $value . "%";
	//exit();
	$i++;
}
return $return;
}

 

this is the function now i try to call it by doing this:

var_dump(trackerHash("0a32654838808aa26828dcdd526ad03ff7360382"));

output:

"82ing(71) "65

 

What is "82ing(71)" ????? and why dosen't it output it like

0a%32%65%48%38%80%8a%a2%68%28%dc%dd%52%6a%d0%3f%f7%36%03%82

 

I have tried printing the the array out and everything seams fine there... anyone have an ide ?

 

 

3672E428DFE497D9DC10B054D2A49EF9F4CE010B

 

Appears to be a hash string. It appears that each pair of characters in that string represent a single byte (in hexadecimal). For instance: "36" is the hexadecimal representation for the character "6"; and 0x72 represents a lower-case "R". These are the first two values in your second example. The parts of the (second) string that start with "%" are, apparently, urlencoded representations of the rest of the string.

 

I'm not explaining this very well ... but, if you pack the first string back into a raw-digest, and then urlencode that value, you get your second value:

 

$hash = '3672E428DFE497D9DC10B054D2A49EF9F4CE010B';
$res  = '6r%E4%28%DF%E4%97%D9%DC%10%B0T%D2%A4%9E%F9%F4%CE%01%0B';

$p = pack('H*', $hash);
print(urlencode($p) . PHP_EOL);
print($res . PHP_EOL);
// prints the exact value in your second string: 6r%E4%28%DF%E4%97%D9%DC%10%B0T%D2%A4%9E%F9%F4%CE%01%0B

// OR GO THE OTHER WAY

$u = unpack('H*', urldecode($res));
print($u[1] . PHP_EOL);
print($hash . PHP_EOL);
// prints the exact value in your first string (well, in lowercase): 3672e428dfe497d9dc10b054d2a49ef9f4ce010b

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.