使用https://github.com/utdemir/bencoder后要从单个文件 torrent 中提取元信息,我在输出的“pieces”部分下看到以下文本-
这是输出的缩写部分 -
'件':'\x8f1g\xdb\x1e\x17\n(\xf9\xbb\xb0&\xa0\xadT9N\xa8L\x89\x97\xf79\x15\x07N
查看 https://wiki.theory.org/BitTorrentSpecification 后我理解这个输出是-
[a] string consisting of the concatenation of all 20-byte SHA1 hash values, one per piece (byte string, i.e. not urlencoded)
但是我看到常量反斜杠“\”,并且想知道这是否类似于十六进制代码,因为 SHA-1 通常输出为十六进制?
最佳答案
您从程序中看到的输出被编码为 Python bytesliteral ,
是不可打印的字节并且 ASCII 被转义。
\x8f1g\xdb\x1e\x17\n(\xf9\xbb\xb0&\xa0\xadT9N\xa8L\x89\x97\xf79\x15\x07N
\x8f
=> 十六进制 0x8F
1g
=> ASCII“1g”
\xdb\x1e\x17
=> 十六进制 0xDB1E17
\n
=> 转义序列,表示 ASCII 换行 (LF)(十六进制 0x0A)
(
=> ASCII "("
\xf9\xbb\xb0
=> 十六进制 0xF9BBB0
等等
关于python - 了解 BitTorrent 片段输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42234766/