Giter VIP home page Giter VIP logo

basencoding's Introduction

basencoding

This package contains a Python 3 module and script for basencoding, which treats each byte sequence as a base-256 number and convert it to another base between 2 and 36.

basencoding (the module)

This provide two functions encode(data, [base]) and decode(data, [base, encoding]) to encode and decode a bytes data using basencoding and return a bytes object.

The argument base is also a bytes and might be in either base-36 (to specify output's case) or base-10 (and 0 for lower, 1 for upper 36).

Because the functions process bytes, so they can deal with all kind of data, text (encoded in any encoding support by Python), binary, etc. For example:

>>> encode(b'CnX', b'g')
b'436e58\n'
>>> decode(encode('Phần mềm tự do muôn năm!'.encode())).decode()
'Phần mềm tự do muôn năm!'

basenc (the script)

This is the front-end for basencoding, which supports both Standard I/O and files. Encoded output will be 1.5 to 8 times larger than the input data, depending on the base chosen to encode. Note that the program is incredibly slow on big data (100kB and above) as it converts the whole data scheme to one integer.

$ basenc -h
usage: basenc [-h] [-v] [-i INFILE] [-o OUTFILE] [-d] [-b BASE] [-e ENCODING]

Encode and decode files using basencoding.

optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -i INFILE, --infile INFILE
                        input file, if not set read standard input
  -o OUTFILE, --outfile OUTFILE
                        output file, if not set read standard output
  -d, --decode          decode the data
  -b BASE, --base BASE  base system between 2 and 36, written in base 36 to
                        specify letters case of output if needed (incase base
                        is 36, use 0 for lowercase, 1 for uppercase). If this
                        is not set, the base will be picked to ensure data is
                        decodable to text in set encoding when decode, and
                        picked randomly when encode.
  -e ENCODING, --encoding ENCODING
                        set encoding, only useful when base is not set
$ echo 48656c6c6f2C20576f726C64210A | basenc -d
Hello, World!
$ basenc -i foobar
56c5A920546869c3AA6e205472756e67204869e1Babf750A
$ basenc -i /usr/bin/python3 -o base_python3 -b 20

If you find any bug or have any suggestion, please fill an issue on Github: https://github.com/McSinyx/basencoding. Enjoy the encoding toy!

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.