[bittorrent] About getting the info hash value from a .torrent file

Brian Dessent brian at dessent.net
Tue Oct 25 03:48:58 EDT 2005


FYP 2005 wrote:

> Below is my content of the torrent.

.torrent files contain binary data, you can't just copy and paste it
into an email and expect it to survive intact.

> Then I try to use sha1 algorithm to get the info hash from the
> torrent.
> However, it seems that the result that i got from the algorithm is
> different from the one that I got from BitComet or TorrentSpy. I am
> quite sure that my algorithm is correct as I just used a sha 1
> function from php.

You're using the right algorithm but you're not hashing the correct
data.  'info' is a key in the dict.  Take its value, and hash that.

There are dozens of BT infohash implementations, I suggest you look at
how they do it: the mainline client, ABC, Azureus, BitTornado,
torrentspy, DehackEd's PHP scripts, any bytemonsoon based tracker,
etc... These are all open source and readily available.

> What are they ?

The binary hashes of each piece.

> It seems that they are byte String . isn't it ?

Huh?

> How to convert those weird characters into readable characters ?

You don't.  It's binary.  That's the point.  If you want to print them
in human readable form you could use hexadecimal.

> Do I need to convert those weird char into readable format before
> finding the info hash value  so that i can get a correct info hash
> value?

No.  If you do any conversion you will get the wrong hash.

Brian



More information about the BitTorrent mailing list