Jump to content

How does uTorrent encode info_hash in GET requests?


Recommended Posts

For example this is a known hash of a test torrent: DDEAB2A22896D5DBC8389D1F5514360C4B09BA7E

however when I receive the GET request from uTorrent, the info_hash parameter looks like:

18겢(8U6K ~

Does anyone have any ideas what is happening?

Thank you

Link to comment
Share on other sites

Okay, well that's better I guess.

Please help me understand what is happening.

Does that parameter have to be decoded in a certain way? All of the other params seem to be simple strings (not sure about peer id).

Link to comment
Share on other sites

I read that again...I am definitely not understanding something.

The specs give this example:

For a 20-byte hash of \x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a,

The right encoded form is %124Vx%9A%BC%DE%F1%23Eg%89%AB%CD%EF%124Vx%9A

but when I actually try encoding \x12\x34\x56\x78\x9a\xbc\xde\xf1\x23\x45\x67\x89\xab\xcd\xef\x12\x34\x56\x78\x9a

I get:


Can you give me a better idea of how to get the right encoded form?

Link to comment
Share on other sites

I changed the code. Now I am able to pass the right encoded example:


through the byte translator and get:


However when I pass the info_hash that the client sends as a GET, into the byte translator it comes out very strange. Some of the SHA1 hash is there, other parts of it don't make any sense to me.

Can you make any sense of this?

Actual hash as shown in uTorrent:


After passing through the same byte translator:


For emphasis:

efbfbd eab2a228e fbfbdefbfbdefbfbdefbfbd38efbfb d1f5514360c4b09 efbfbd7e

DD EAB2A228 96D5DBC8389 D1F5514360C4B09 BA7E

Thanks again

Link to comment
Share on other sites

Look at the first unread character. If it is a %, pull the following two characters in the received info_hash out as the hex value of that byte. Else, convert that character into a two-character string representation of the character's hex value. Repeat until you reach the end of info_hash.

If you're actually receiving a 20-byte string, then well... just look at the string one byte at a time, and individually convert each byte into its respective two-character hex string.

Link to comment
Share on other sites

Alright, thank you for the help. Slowly but surely, I was funneled into the problem.

Surprisingly it was translating the bytes properly — I actually didn't have a byte translator before post one, so thanks for that.

When I tried to follow Ultima's solution though, I was back at square (post) one, which eventually led me to discover that it was a code page issue on the server side.

Well, this part works now. I hope the rest isn't so baffling =!

Still have to read the code page wiki...wth...

Link to comment
Share on other sites


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

  • Create New...