Git Product home page Git Product logo

l2p2p's Introduction

L2P2P

bencoding

See references below for a closer understanding of bencoding, as well as the broader BitTorrent specifications.

decoding bencoded data

>>> from bencoding import Decoder
>>>
>>> bencoded_int  = b'i12345e'
>>> bencoded_str  = b'9:bencoding'
>>> bencoded_list = b'l5:hello3:how3:are3:youi12345ee'
>>> bencoded_dict = b'd4:type4:dict8:told_you2:soe'
>>>
>>> from bencoding import Decoder, Encoder
>>> Decoder(bencoded_int).decode()
12345
>>> Decoder(bencoded_str).decode()
b'bencoding'
>>> Decoder(bencoded_list).decode()
[b'hello', b'how', b'are', b'you', 12345]
>>> Decoder(bencoded_dict).decode()
OrderedDict([(b'type', b'dict'), (b'told_you', b'so')])

encoding bencoded data

>>> from bencoding import Encoder
>>>
>>> i = 12345
>>> s = 'hi there thanks for stopping by'
>>> l = ['hi', 'there', 'thanks', 'for', 'checking', 'out', 'this', 'list']
>>> d = {'this': 'is', 'definitely': 'a', 'dict': 'type'}
>>> cx = ['everything', 101010, 'works', {'pretty': 'okay'}]
>>>
>>> Encoder(i).encode()
b'i12345e'
>>> Encoder(s).encode()
b'31:hi there thanks for stopping by'
>>> Encoder(l).encode()
bytearray(b'l2:hi5:there6:thanks3:for8:checking3:out4:this4:liste')
>>> Encoder(d).encode()
bytearray(b'd4:this2:is10:definitely1:a4:dict4:typee')
>>> Encoder(cx).encode()
bytearray(b'l10:everythingi101010e5:worksd6:pretty4:okayee')

references

l2p2p's People

Contributors

oaao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.