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

Silvan Zurbruegg silvan at bitflux.ch
Tue Oct 25 04:03:46 EDT 2005


FYP 2005 schrieb:

> I have some silly question here.
> I'm going to get the info hash from a .torrent file. From the 
> specification. the info hash is a 20-byte SHA1 hash of the /value/ of 
> the *info* key from the Metainfo file.
> Below is my content of the torrent.
> d8:announce35: 
> http://bt.gamesir.com:6969/announce13:announce-listll35:http://bt.gamesir.com:6969/announceel35:http://bt.gamesir.com:8080/announceel35:http://bt.gamesir.com:8000/announceel39:http://tlfbt.eastgame.net:6969/announceel39:http://tracker.btzero.net:8080/announceel37:http://tlfbt.eastgame.net:81/announceel39:http://tracker.btzero.net:8000/announceee10:created 
> <http://bt.gamesir.com:6969/announce13:announce-listll35:http://bt.gamesir.com:6969/announceel35:http://bt.gamesir.com:8080/announceel35:http://bt.gamesir.com:8000/announceel39:http://tlfbt.eastgame.net:6969/announceel39:http://tracker.btzero.net:8080/announceel37:http://tlfbt.eastgame.net:81/announceel39:http://tracker.btzero.net:8000/announceee10:created> 
> by13:BitComet/0.6013:creation 
> datei1130084762e8:encoding4:Big54:infod6:lengthi46029e4:name24:PwC(CampusInterview).pdf10:name.utf-824:PwC(CampusInterview).pdf12:piece 
> lengthi32768e6:pieces40:eqn?cc甖灉??恨?L}s?ll?0?剌ee
> 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.
> When I look at the content inside the torrent.
> I found some strange or weird characters after pieces40:. ie. 
> :eqn?cc甖灉??恨?L}s?ll?0?剌
> What are they ?
> It seems that they are byte String . isn't it ?

When encoding pieces with php's sha1(), make sure to set the raw_output 
argument.
(sha1($piece, true) // php > 5 only). That returns the hash in raw 
binary format (And that's why
the weird characters).


How to convert those weird characters into readable characters ?

> 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?

Nope. Base for the info_hash is the bencoded string of the info key.



HTH+greets
silvan






More information about the BitTorrent mailing list