TORRENT to MAGNET / JSON
Decode .torrent Bencode, compute SHA-1 info_hash & extract Magnet link + files — 100% private client-side processing.
Active Converter
TORRENT to MAGNET / JSON: Computing BitTorrent Info-Hashes & File Trees Locally
Technical Anatomy of Bencoded .TORRENT Files
Defined in BEP-0003 (BitTorrent Specification), a .torrent file is a compact Bencode binary dictionary. Bencode supports just four data types: byte strings prefixed with decimal length (8:announce), integers delimited by i...e (i262144e), lists (l...e), and lexicographically sorted dictionaries (d...e).
Inside the root dictionary sits the critical 4:info sub-dictionary containing the torrent name, piece length, concatenated 20-byte SHA-1 piece hashes, and either a single file length or a files list. To generate an authentic Magnet URI (magnet:?xt=urn:btih:<40-hex-hash>&dn=...&tr=...), our parser records the exact start and end byte offsets of the raw info dictionary and feeds that exact slice to crypto.subtle.digest('SHA-1', infoSlice).
Raw Bencode Metadata vs. Generated Magnet Link & JSON
# Input: Raw Bencode Prefix (ubuntu-24.04-desktop.torrent)
d8:announce39:https://torrent.ubuntu.com/announce4:infod6:lengthi6123456789e4:name23:ubuntu-24.04-amd64.iso...e
# Computed Magnet Link & JSON Output:
magnet:?xt=urn:btih:2c6b6858d61da9543d4231a71db4b1c9264b0685&dn=ubuntu-24.04-amd64.iso&tr=https%3A%2F%2Ftorrent.ubuntu.com%2Fannounce
Real-World Software & Hardware Ecosystem
Linux ISO mirrors, open-dataset researchers (Academic Torrents, Internet Archive), and seedbox users convert .torrent files into lightweight Magnet links or JSON file inventories for qBittorrent, Transmission, Deluge, aria2c, and mobile clients without keeping dozens of .torrent files cluttering their downloads folder.
Troubleshooting & Edge Cases
- BitTorrent v2 Hybrid Torrents (BEP-0052): Newer v2-only torrents use SHA-256
btmhhashes and afile treedictionary instead of v1files; hybrid torrents carry both v1 SHA-1 and v2 metadata so standardbtihMagnet links still work universally. - Preserving Raw Info Bytes: Re-encoding the
infodictionary with slightly different key ordering changes the SHA-1 hash completely. Our decoder slices the original raw bytes directly so thebtihhash matches qBittorrent 100%. - Batch Converting Multiple .TORRENT Files: Drop a folder of
.torrentfiles to extract every Magnet URI and JSON file tree in a single Batch ZIP download.
BEP-0003 Bencode Grammar Reference
| Bencode Type | Syntax Pattern | Concrete Example |
|---|---|---|
| Byte String | <len>:<bytes> | 4:info |
| Integer | i<base10>e | i262144e (256 KB piece) |
| List | l<items>e | l4:docs9:README.mde |
| Dictionary | d<key><val>e | d6:lengthi1024ee |
Step-by-Step SHA-1 Info-Hash Derivation
- Locate the
4:infoKey: Our streaming Bencode parser traverses the root dictionary without converting binary piece hashes to UTF-8 strings (which would corrupt high bytes>= 0x80). - Slice Exact Raw Bytes: The parser records the starting byte offset of the
infodictionary's openingdand its matching closinge. - Hash via WebCrypto SHA-1: That exact byte slice is passed to
crypto.subtle.digest('SHA-1', infoBytes)to yield the 20-byte (40-hex-character)urn:btihhash. - Assemble RFC 3986 Magnet URI: The display name (
dn) and tracker URLs (tr) are percent-encoded and appended into a ready-to-click Magnet link.
Understanding Piece Length, Tracker Lists & DHT Discovery
Every .torrent splits its payload into fixed-size cryptographic chunks—commonly 256 KB, 1 MB, or 4 MB—declared by piece length inside the info dictionary. Each piece has a 20-byte SHA-1 hash concatenated into the binary pieces field so P2P clients verify every downloaded block against corruption automatically.
When you convert a .torrent into a Magnet URI, the link carries only the 40-character btih hash, display name (dn), and optional tracker URLs (tr); the client then fetches the full info dictionary on demand from peers via BEP-0009 metadata exchange over DHT. Exporting the JSON file tree locally first lets you verify exact filenames and total gigabytes before adding the Magnet link to qBittorrent, Transmission, or aria2c.
Remember that public DHT discovery works best when a Magnet URI includes at least two active UDP or HTTPS announce trackers alongside the btih hash. When archiving Linux distribution releases for offline lab networks, keeping both the lightweight Magnet link and the exported JSON file manifest provides instant cryptographic verification of every filename and byte count.
Frequently Asked Questions
A .torrent file is encoded in Bencode—a binary-safe format of dictionaries (d...e), lists (l...e), integers (i...e), and length-prefixed byte strings (4:info). Our client-side Bencode decoder locates the exact raw byte slice of the 'info' dictionary and hashes it with WebCrypto SHA-1 to produce the 40-character hexadecimal info_hash.
Yes. Export to .JSON or preview in the workbench to see the torrent's display name, announce tracker URLs, piece length, and every file path + size listed inside single-file or multi-file info.files dictionaries.
Private trackers set info.private = 1 inside the Bencode dictionary to instruct clients like qBittorrent or Transmission to disable DHT and Peer Exchange (PEX). Note that Magnet links omit private passkey data unless the announce URL is appended.
No. It strictly parses the tiny local .torrent metadata file in your browser to extract the Magnet link, SHA-1 info_hash, trackers, and file manifest—making zero P2P network connections.