[英]Decode Torrent Hash of Torrent tracker scrape?
我正在使用BEncoded PHP Library來解碼來自Bittorrent跟蹤器的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 )
我的問題我在上面的輸出中的問題是如何解碼輸出中的那些神秘字母。
鏈接: http ://wiki.vuze.com/w/Scrape發布者user3690414幾乎解釋了不同的鍵代表什么。
要解釋原始的bencoded字符串:
d5:filesd20:¼€™rÄ2ÞÊþVA .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
你需要了解bencoding是如何工作的: https ://wiki.theory.org/BitTorrentSpecification#Bencoding
這里要知道的最重要的是,bencoded字典中的每個條目都是Key,Value -pair。
其中Key是一個字節字符串
和值以下類型之一: 字節字符串 , 整數 , 列表或字典 。
考慮到這一點,原始字符串可以像這樣分解:
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信息哈希[¼€™rÄ2ÞÊþVA。]á^ |]
更人性化,我建議您將其輸出為40字節的十六進制編碼字符串:
0xBC801B9D9972C432DECAFE56410F092E5DE15EA6
如果您指的是files
數組的錯位密鑰,那么它是原始的infohash - 請查看規范:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.