0.0
No release in over 3 years
Low commit activity in last 3 years
Binary to text encoding of data is commonly used for transmission when the channel does not support binary data. Common formats are Base16 (also known as hexadecimal), Base32, and Base64. This tool allows the creation of an encoder for any power-of-2 base and alphabet, allowing even to customize the padding to be used, if any.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

 Project Readme

RadixEncoding

Encode and decode strings using standard or custom versions of radix-based encodings, such as Base16 (hexadecimal encoding), Base32 and Base64.

Thought for flexibility.

Installation

Add this line to your application's Gemfile:

gem "radix_encoding"

And then execute:

$ bundle install

Or install it yourself as:

$ gem install radix_encoding

Usage

Using a standard encoding

The following standard encodings are currently fully supported, and available through constants under RadixEncoding:

  • Standard Hexadecimal encoding through RadixEncoding::BASE16 (RFC4648);
  • Standard Base32 encoding through RadixEncoding::BASE32 (RFC4648);
  • Standard Base64 encoding through RadixEncoding::BASE64 (RFC4648);

Using a custom encoding

To create your own encoding variant, use the RadixEncoding::Encoding class.

digest_hexencode = RadixEncoding::Encoding.new(
  alphabet: "0123456789abcdef",
  radix: 16,
)

⚠️ Caveats for the current implementation:

  • alphabet is only validated to have a length greater or equal to radix;
  • radix must be a power of 2, or it fall-back to the greatest power of 2 which is less than radix;
  • padding should be a string with a single character, otherwise the behaviour is unspecified.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/subvisual/ruby-radix-encoding.

License

RadixEncoding is copyright © 2020 Subvisual, Lda.

It is open-source, made available for free, and is subject to the terms in its license.

About

RadixEncoding was created and is maintained with ❤️ by Subvisual.

Subvisual