Skip to content

Commit

Permalink
[Add]: Added Bencoding algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
omjogani committed Jan 13, 2024
1 parent b2b70ef commit 2c91bd3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions _posts/2023-11-01-bencoding-algorithm
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Bencoding Algorithm - Torrent
date: 2023-10-05 10:00:00 -500
categories: [algorithm]
tags: [algorithm, torrent, bencoding]
---


### Bencoding

→ Torrent file are ‘Bencoded’ and to extract the above fields we would need to parse the torrent file (Bencoded).

→ When you download the torrent file and give it to your client in order to download the content of the file. Client will first understand and extract the content described above. then it will get to know the location and where to get the actual piece of data.

### Bencoding Specification

| Bencoding | Supports : Strings, list, integers, and dictionaries |
| --- | --- |
| Strings | Format : `<length>` : `<string>` Example : om → 2 : om |
| Integers | Format : i`<integer>`e, Example : 10 → i10e |
| list | Format : l`<bencoded values>`e, Example : [”a”, “be”, 1] → l 1:a 2:be i1e e |
| Dictionary | Format : d`<bencoded string>` `<bencoded values>`….e, Example : { “a”: 1, “be”: 2} → d 1:a i1e 2:be i2e e (key value…) |

0 comments on commit 2c91bd3

Please sign in to comment.