From: Oleg Broytman Date: Mon, 3 Feb 2025 20:38:58 +0000 (+0300) Subject: Feat: Calculate info-hash X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=dcf807f53b646431b9c4d7f46371e9be2838b9e6;p=bittorrent.git Feat: Calculate info-hash --- diff --git a/torrent-info-hash b/torrent-info-hash new file mode 100755 index 0000000..92e628b --- /dev/null +++ b/torrent-info-hash @@ -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())