解码 Torrent Tracker Scrape 的 Torrent Hash?

10
我正在使用 BEncoded PHP Library 来解码 BitTorrent Tracker 的 bencoded 响应。
Tracker 的响应是:
d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee

使用以下代码解码后:

require 'bencoded.php';

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

输出结果为:

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

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


1
您可以直接在此处查看跟踪器响应:http://exodus.desync.com:6969/scrape/?info_hash=%BC%80%1B%9D%99r%C42%DE%CA%FEVA%0F%09.%5D%E1%5E%A6 - user3155632
2个回答

11

这个链接:http://wiki.vuze.com/w/Scrape由用户3690414发布,基本解释了不同键的含义。

要解释原始bencoded字符串:

d5:filesd20:¼€™rÄ2ÞÊþVA  .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee

你需要了解bencoding的工作原理:https://wiki.theory.org/BitTorrentSpecification#Bencoding

这里最重要的是,bencoded字典中的每个条目都是一个键值对
其中是一个字节字符串
可以是以下类型之一:字节字符串整数列表字典

有了这个概念,原始字符串可以被分解如下:

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

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

编辑。
如果您想将160位大端SHA1 info-hash [¼€™rÄ2ÞÊþVA .]á^¦]更容易理解,请将其输出为40字节的十六进制编码字符串:
0xBC801B9D9972C432DECAFE56410F092E5DE15EA6


3
需要将它转换为40字节的十六进制编码字符串,这样才能让人类读懂,对吗? - user3155632

2

1
但是我该如何正确地显示它呢?@Proger_XP - user3155632

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接