Giter VIP home page Giter VIP logo

libencode.sh's Introduction

libencode.sh

Base64 family of binary-to-text encoding algorithms implemented in shell.

Contents

  1. Libraries
  2. Compatibility
  3. Requirements
  4. Demo
  5. License

Libraries

  • encode.sh is a general purpose library exposing various functionalities like conversion from decimal to binary or string padding. It exports the following functions:
    • enum
    • leftpad
    • rightpad
    • ord
    • chr
    • dectobin
    • bintodec
    • dectohex
    • swap32
  • base64.sh implements the Base64, Base64 URL, Base32, Base32 Hex and Base16 encoding algorithms. The following functions are considered public:
    • base64_encode
    • base64url_encode
    • base32_encode
    • base32hex_encode
    • base16_encode
    • hex_encode

Compatibility

libencode.sh targets shells supporting the KSH “local” extension. It is therefore known to run with the following shells:

  • Debian Almquist SHell - dash ;
  • GNU Bourne-Again SHell - bash ;
  • MirBSD Korn SHell - mksh ;
  • OpenBSD Korn SHell - oksh ;
  • Yet Another SHell - yash.

Additionally zsh is fully compatible with encode.sh but doesn't work well with base64.sh. In both case the option SH_WORD_SPLIT must be activated.

Requirements

The following utilities are needed by libencode:

  • printf (built-in shell version is fine) ;
  • bc ;
  • cut ;
  • grep ;
  • jot or seq ;
  • sed.

Demo

A simple script wrapping all of the binary-to-text functions is provided: demo.sh. It is a Korn Shell script using the autoload feature, so a directory populated with a file for every functions exported by libencode and a correct FPATH environnement variable are mandatory :

$ mkdir -p ~/sh
$ cd ~/sh
$ ln -s $LIBENCODEPATH/base64.sh base16_encode
$ ln -s $LIBENCODEPATH/base64.sh hex_encode
$ ln -s $LIBENCODEPATH/base64.sh base32_encode
$ ln -s $LIBENCODEPATH/base64.sh base32hex_encode
$ ln -s $LIBENCODEPATH/base64.sh base64_encode
$ ln -s $LIBENCODEPATH/base64.sh base64url_encode
$ grep -E '^[a-z0-9]+\(' $LIBENCODEPATH/encode.sh | while read func; do
> func="$(echo $func | cut -d'(' -f1)";
> ln -s $LIBENCODEPATH/encode.sh "$func";
> done
$ export FPATH=$FPATH:$HOME/sh

The environnement is now ready, demo.sh is usable :

$ mksh $LIBENCODEPATH/demo.sh -e base64 -s foobar
Zm9vYmFy
$ echo -n foobar | base64
Zm9vYmFy

It is also possible to use autoload in an interactive korn shell to use base64_encode directly :

$ autoload base64_encode
$ base64_encode foobar
Zm9vYmFy

Of course all of these awkward steps can be bypassed if you just this project as intended: as a library.

License

All the code is licensed under the ISC License. It's free, not GPLed !

libencode.sh's People

Contributors

tleguern avatar

Stargazers

 avatar  avatar  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.