Encode and decode Bencode, the data format used by BitTorrent .torrent files. Four types are supported: strings (len:bytes), integers (i<n>e), lists (l…e), and dictionaries (d…e). Binary-safe strings are surfaced as hex when they aren't valid UTF‑8.
Bencode strings are raw byte sequences. When a string isn't valid UTF‑8 (for example, the pieces field of a torrent — a concatenation of SHA‑1 digests) this tool represents it in JSON as {"__hex__":"…"}, and will round-trip it back to bytes on re-encode. Dictionaries are serialized with keys sorted lexicographically as required by the spec. Integers are arbitrary precision via BigInt; values that fit in a safe JS number decode as Number, larger ones as BigInt strings with n suffix.