GithubHelp home page GithubHelp logo

bitdoodle's Introduction

BitDoodle!

Python Class for dealing with variable length bit doodles.

Description:

Bit Doodle is a class designed for working with variable length bit fields. While the class can technically be used for anything, it is catered towards IPv4 and IPv6 addresses. The main methods are join and disjoin, which will take a list of variable length fields and a list of values and join them together to a single value, or disjoin which will take a single value and a list of bit lengths, and break the original value into its multiple parts.

EXAMPLES:

Basic useage simple example

from BitDoodle import BitDoodle
format_ = [8, 8, 8, 8]
dood = BitDoodle(format_)
dood.join([10, 20, 30, 40])
IPv4Address(u'10.20.30.40')
dood.total_bit_length
32

Not so obvious IPv4 example

Imagine if a standard IP address was broken up into meaningful pieces. For example the first 8 bits are a static 10, but the next 5 bits represent your datacenter, and the next 4 bits might represent the security zone, and the next 4 bits might represent the pod number, and so on. Given a format and values to put into the fields, you can generate a meaningful IP address.

format_ = [8, 5, 4, 5, 4, 6]
dood = BitDoodle(format_)
dood.join([10, 4, 0, 1, 4, 30])
IPv4Address(u'10.32.5.30')

Not so obvious IPv6 example

This is the same as above, but for IPv6. If ARIN (or your RIR) gave you a /40, the first 40 bits would be static, then the next 24 bits could mean something specific to your use case, split up however you want. Finally the last 64 are the host, which you could also break down further if you wanted. This is more to show BitDoodle working fine with very large numbers.

format_ = [40, 6, 4, 6, 4, 4, 64]
dood = BitDoodle(format_)
dood.join([0x200199aa00, 4, 0, 1, 4, 10, 255])
IPv6Address(u'2001:99aa:10:14a::ff')

Disjoin example

Disjoin does the opposite of join. Given a format and an integer (in this case, represented as a binary number / IP address), return the values of each section. So just like above, if you knew the IP address you could find out the data center, security zone, pod, etc, of each field.

format_ = [8, 5, 4, 5, 4, 6]
dood = BitDoodle(format_)
dood.disjoin(0b00001010000011111111111100101101)
[10L, 1, 15, 31, 12, 45]

bitdoodle's People

Contributors

jaredn avatar

Watchers

 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.