python - 了解 BitTorrent 片段输出

标签 python sha1 bittorrent

使用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/

相关文章:

python - 对于 Pandas 系列,s.sort_index(inplace=True) 不应该改变 s 吗?

python - 将函数应用于返回多行的 pandas 数据框

c# - 在 Java 和 C# 中计算 SHA-1 哈希

bittorrent - 如何从 Torrent Tracker 响应中获取对等列表

ruby - BitTorrent 对等握手

python - 查找两个列表中最常见元素的索引

amazon-web-services - 为什么 base64 是 sha1/sha256 哈希?

javascript - Node.js HTTP 流请求与 Express.js 请求对象

python - 从 udp 和 http torrent tracker 响应获取 IP 地址

python - Django 立即保存并返回对象(使用自定义 pk)