Skip to content

Instantly share code, notes, and snippets.

@nbrochu
Created September 10, 2009 05:07
Show Gist options
  • Save nbrochu/184324 to your computer and use it in GitHub Desktop.
Save nbrochu/184324 to your computer and use it in GitHub Desktop.
# Generating the info_hash from a torrent file (binary & urlencoded)
require 'bencode' # sudo gem install bencode
require 'digest/sha1'
require 'cgi' # Not needed in rails
decoded_torrent = BEncode.load_file("public/files/example.torrent")
info_hash = ([Digest::SHA1.hexdigest(decoded_torrent["info"].bencode)].pack("H*")).downcase
url_encoded_info_hash = CGI.escape(info_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment