Cineex Posted August 14, 2011 Share Posted August 14, 2011 Im trying to get this: 3672E428DFE497D9DC10B054D2A49EF9F4CE010B to look like this: 6r%E4%28%DF%E4%97%D9%DC%10%B0T%D2%A4%9E%F9%F4%CE%01%0B anyone have an ide of a function that whould do this ? Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/ Share on other sites More sharing options...
voip03 Posted August 14, 2011 Share Posted August 14, 2011 this is md5 result? what is your code? Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257185 Share on other sites More sharing options...
Cineex Posted August 14, 2011 Author Share Posted August 14, 2011 it's an info hash from a torrent. The second one is what the program sends to the torrent tracker and the first one is the info-hash from a magnet link Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257237 Share on other sites More sharing options...
Cineex Posted August 14, 2011 Author Share Posted August 14, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257348 Share on other sites More sharing options...
xyph Posted August 14, 2011 Share Posted August 14, 2011 I'm not sure why it's converted 3672 into 6r. Once I've solved that, the rest is easy. Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257362 Share on other sites More sharing options...
DavidAM Posted August 14, 2011 Share Posted August 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257385 Share on other sites More sharing options...
Cineex Posted August 14, 2011 Author Share Posted August 14, 2011 Thanks that was exactly what i needed, your explanation was good Quote Link to comment https://forums.phpfreaks.com/topic/244764-hash-convert-function/#findComment-1257411 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.