tags:

views:

305

answers:

1

Hello,

I am trying to create my own torrent tracker but dont know how to generate info_hash that is used xbtt to track torrents.

Is this possible with php?

I am using this function to bencode and decode http://paste.lisp.org/display/17178

Is this the correct hash?

$nn = file_get_contents('my.torrent');
$file = bdecode($nn);
$hash = sha1( bencode($file[info]) );

Thank You.

+1  A: 

According to the bittorrent specification the info_hash is an urlencoded 20-byte SHA1 hash of the value of the info key from the Metainfo file.

You can calculate the sha1 hash of a string in php using the sha1 function and url encode ot with the urlencode function.

UPDATE:

Your method is not correct. You need to bdecode the torrent file, which you have already done. But you need to calculate the info_hash based on the value of the info key from the Metainfo (torrent) file. When you have done that, you still need to urlencode the result, which it seems is also missing from your current implementation.

klausbyskov
Please check my editted post
Shishant
@Shishant: please see my updataed answer.
klausbyskov
Yes, Finally figured it out.
Shishant