Decode Torrent Хеш торрент трекер? - программирование

Decode Torrent Хеш торрент трекер?

Я использую BEncoded PHP Library для декодирования bencoded ответа от трекера Bittorrent.

Ответ 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 )

Моя проблема моя проблема в вышеприведенном выпуске заключается в том, как декодировать эти таинственные буквы на выходе.

4b9b3361

Ответ 1

Ссылка: http://wiki.vuze.com/w/Scrape, опубликованная user3690414, в значительной степени объясняет, что означают разные клавиши.

Чтобы интерпретировать исходную строку bencoded:

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

вам нужно понять, как работает bencoding: https://wiki.theory.org/BitTorrentSpecification#Bencoding

Самое главное знать здесь - это то, что каждая запись в закодированном словаре - это 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

Надеемся, что это поможет понять выход из "bencoded.php".

редактировать.
Если вы хотите сделать 160-битный большой endian SHA1 info-hash [¼ € ™ rÄ2ÞÊþVA.] Á ^ |]
более понятный для человека, я предлагаю вам вывести его как 40-байтную шестнадцатеричную кодировку:
0xBC801B9D9972C432DECAFE56410F092E5DE15EA6