3

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.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
George
  • 113
  • 1
  • 1
  • 6
  • All %nn triplets are hexadecimal representations of the byte, everything else is not encoded, what do you want to do with the binary data? – Alex K. Apr 12 '11 at 16:01
  • I thought I could get a better representation that this one. The purpose would be to build a tracker and I was confused about the information that should go into the database. – George Apr 14 '11 at 10:20
  • It turns out that the best representation is that one, and I shouldn't decode it. I will use it just the way it is. – George Apr 21 '11 at 08:25

2 Answers2

6

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.

Neon Flash
  • 3,113
  • 12
  • 58
  • 96
0

the method you use to 'decode' depends upon how it was 'encoded'.

When choosing the encoding method:

escape() will not encode: @*/+

encodeURI() will not encode: ~!@#$&*()=:/,;?+'

encodeURIComponent() will not encode: ~!*()'

you may be looking at some form of double encoding.

herostwist
  • 3,778
  • 1
  • 26
  • 34