Git Product home page Git Product logo

basexx's Introduction

basexx

travis

A Lua library for base2, base16, base32, base64, base85 decoding and encoding of data strings.

API

For every supported format has basexx a from and to function.

The from functions have two parameters:

  • str which represent the encoded string that should be decoded

  • ignore is an optional set of characters that should be ignored in the string, see the from_bit and from_hex examples

The from functions return a string if the string can be decoded, otherwise nil and an error message.

The to functions have just one parameter:

  • str the data string that should be encoded

The to_z85 function can return nil and an error message, all other functions return allways the encoded string.

from_bit / to_bit

Converts a byte string to a bitfield string.

  • 0, O and o maps to the same value

  • 1, I, i, L and l maps to the same value

basexx.to_bit( "ACDC" ) --> 01000001010000110100010001000011
basexx.from_bit( "01000001010000110100010001000011" ) --> ACDC
basexx.from_bit( "o1ooooo1o1oooo11" ) --> AC
basexx.from_bit( "Oioooooi Oiooooii\n", " \n" ) --> AC

from_hex / to_hex

Converts a byte string to a uppercase hex data string.

basexx.to_hex( "Hello world!" ) --> 48656C6C6F20776F726C6421
basexx.from_hex( "4865-6C6C 6F20-776F 726C-6421", "- " ) --> Hello world!
basexx.from_hex( "48656c6c6f20776f726c6421" ) --> Hello world!

from_base32 / to_base32

Converts a byte string to a base32(_rfc3548) uppercase data string.

  • It’s case insensitive

basexx.to_base32( "chunky bacon!" ) --> MNUHK3TLPEQGEYLDN5XCC===
basexx.from_base32( "MNUHK3TLPEQGEYLDN5XCC===" ) --> chunky bacon!

from_crockford / to_crockford

Converts a byte string to a base32(crockford) uppercase data string. The optional check value is not implemented.

  • It’s case insensitive

  • 1, I, i, L and l maps to the same value

  • 0, O and o maps to the same value

string.lower( basexx.to_crockford( "Hello World" ) ) --> 91jprv3f41bpywkccg
basexx.from_crockford( "axqqeb10d5t20wk5c5p6ry90exqq4tvk44" ) --> Wow, it really works!

from_base64 / to_base64

Converts a byte string to a base64 data string.

basexx.to_base64( "Man") --> TWFu
basexx.from_base64( "TWFu" ) --> Man

from_url64 / to_url64

Same as above, but uses a URL Safe base64 alphabet and no padding.

from_z85 / to_z85

Converts a byte string to a base85(ZeroMQ) data string. to_z85 expects only a binary string that length is divisible by 4 with no remainder, and from_z85 expects only printable a string that length is divisible by 5 with no remainder.

basexx.to_z85( "1234" ) --> f!$Kw
basexx.from_z85( "f!$Kw" ) --> 1234

Installation

To install the version 0.4.0 of basexx use LuaRocks with the following line.

luarocks install basexx

If you want to use the current development version, clone this repository and use LuaRocks with the following command.

luarocks make dist/basexx-scm-0.rockspec

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.