]> git.phdru.name Git - bittorrent.git/commitdiff
Feat: Calculate info-hash
authorOleg Broytman <phd@phdru.name>
Mon, 3 Feb 2025 20:38:58 +0000 (23:38 +0300)
committerOleg Broytman <phd@phdru.name>
Sun, 31 Aug 2025 20:38:58 +0000 (23:38 +0300)
torrent-info-hash [new file with mode: 0755]

diff --git a/torrent-info-hash b/torrent-info-hash
new file mode 100755 (executable)
index 0000000..92e628b
--- /dev/null
@@ -0,0 +1,17 @@
+#! /usr/bin/env python3
+
+import sys
+from hashlib import sha1
+
+from bencoder import encode
+from eff_bdecode import eff_bdecode
+
+torrent_file = open(sys.argv[1], 'rb')
+data = torrent_file.read()
+torrent_file.close()
+
+data = eff_bdecode(data)
+info = data[b'info']
+
+encoded_info = encode(info)
+print(sha1(encoded_info).hexdigest())