解码Torrent跟踪器的Torrent Hash?

use*_*632 10 php hash bittorrent tracker

我正在使用BEncoded PHP Library来解码来自Bittorrent跟踪器的bencoded响应.

Tracker的回应是:

d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
Run Code Online (Sandbox Code Playgroud)

使用以下代码解码后:

require 'bencoded.php';

$be = new BEncoded;
//Response saved in scrape.txt
$data =file_get_contents('scrape.txt');
print_r($be->Decode($data));
Run Code Online (Sandbox Code Playgroud)

输出是:

Array ( [files] => Array ( [¼€™rÄ2ÞÊþVA  .]á^¦] => Array ( [complete] => 285 [downloaded] => 22911 [incomplete] => 9 [isDct] => 1 ) [isDct] => 1 ) [isDct] => 1 )
Run Code Online (Sandbox Code Playgroud)

我的问题 我在上面的输出中的问题是如何解码输出中的那些神秘字母.

Enc*_*mbe 11

链接:http://wiki.vuze.com/w/Scrape发布者user3690414几乎解释了不同的键代表什么.

要解释原始的bencoded字符串:

d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
Run Code Online (Sandbox Code Playgroud)

你需要了解bencoding是如何工作的:https://wiki.theory.org/BitTorrentSpecification#Bencoding

这里要知道的最重要的是,bencoded字典中的每个条目都是Key,Value -pair.
其中的关键是一个字节的字符串
以下类型之一:字节串,整数,一个列表或者一个字典.

考虑到这一点,原始字符串可以像这样分解:

d               // The first d indicates the start of the Root dictionary
 5:files            // that has a Key with a 5 byte string name 'files',
  d                     // the value of the 'files'-key is a second dictionary
   20:¼€™rÄ2ÞÊþVA  .]á^¦    // that has a Key 20 byte = 160 bit big endian SHA1 info-hash
    d                       // the value of that key is a third dictionary
     8:complete                 // that has a Key with a 8 byte string name 'complete',
      i285e                         // the value of that key is a Integer=285
     10:downloaded              // that has a Key with a 10 byte string name 'downloaded',
      i22911e                       // the value of that key is a Integer=22911
     10:incomplete              // that has a Key with a 10 byte string name 'incomplete',
      i9e                           // the value of that key is a Integer=9
    e                       // this e indicates the end of the third dictionary
  e                     // this e indicates the end of the second dictionary
e               // this e indicates the end of the Root dictionary
Run Code Online (Sandbox Code Playgroud)

希望这有助于理解'bencoded.php'的输出.

编辑.
如果你想让160位大端的SHA1 info-hash [¼€™rÄ2ÞÊþVA.]á^ |]
更具人性化,我建议你把它输出为40字节的十六进制编码字符串:
0xBC801B9D9972C432DECAFE56410F092E5DE15EA6

  • 所以它必须被转换为40byte hexencoded字符串,以使其人类可读? (3认同)