From dcf807f53b646431b9c4d7f46371e9be2838b9e6 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Mon, 3 Feb 2025 23:38:58 +0300 Subject: [PATCH] Feat: Calculate info-hash --- torrent-info-hash | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 torrent-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()) -- 2.39.5