I have the following tracker request:
"info_hash=%92%c345%c0%28%15%e4rr%b1y%17%b7%cbs%0a%ef%9a%fc&peer_id=-UT2210-%2abP%b2%c23~NaN7-%7c%0f%1f&port=56541&uploaded=0&downloaded=0&left=461680&corrupt=0&key=6AD19369&event=started&numwant=200&compact=1&no_peer_id=1"
and I would like to decode the info_hash
and peer_id
fields in JavaScript.
I've tried the unescape()
, decodeURI()
and decodeURIComponent()
functions but they didn't return the expected results.
The info hash present in the HTTP GET Request to the Tracker can be decoded as follows:
If there's a '%' character, then the next 2 characters are a part of the original 40 char SHA-1 hash.
so, you can break the encoded info_hash as follows:
%92 %c3 4 5 %c0 %28 %15 %e4 r r %b1 y %17 %b7 %cb s %0a %ef %9a %fc
All the 2 char groups prefixed with the '%' symbol belong to the original hash.
Now, for the remaining characters. We need to find the corresponding Hex value of them. You can use asciitable for reference.
For instance, 4 in base 10 is 34 in hex.
Combining all together this way we get:
92c33435c02815e47272b17917b7cb730aef9afc -> SHA-1 hash of the torrent file.
The peer_id will give us information about the client name and version. In this case:
-UT2210-%2abP%b2%c23~NaN7-%7c%0f%1f
This is in Azureus format.
UT corresponds to µTorrent and 2210 gives us the version.
The process of decoding can be automated using a Perl Script easily.