Gem Version

Base85

Base85 is a pure Ruby gem to encode/decode data using Base85 encodings.

It handles mulitple alphabets:

  • standard (original) one,
  • Ascii85 (Adobe version, very similar to standard one but with start and end markers, and a special 'z' character for 4 null bytes),
  • Z85 from ZeroMQ,
  • RFC1924.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add base85

If bundler is not being used to manage dependencies, install the gem by executing:

gem install base85

Usage

CLI

base85 command line tool may be used to decode/encode base85 dialects on command line.

# Encode data from STDIN to STDOUT
echo "text to encode" | base85
# Encode using given alphabet (standard (default one), z85, ascii85 or rfc1924)
echo "text to encode" | base85 -a z85
# Output data is wrapped to 72 columns by default (as do base64)
# To change this value, use -w option (0 to deactivate wrapping)
echo "text to encode" | base85 -a rfc1924 -w 0

# Encode file to STDOUT
base85 -a ascii85 -w 40 myfile

# Decode data from STDIN to STDOUT
echo "aaaaa" | base85 -d
# Encode using given alphabet (standard (default one), z85, ascii85 or rfc1924)
echo "aaaaa" | base85 -d -a z85

# Decode file to STDOUT
base85 -d -a rfc1924 myfile

Ruby library

To encode a string:

require "base85"

# Use standard alphabet
Base85.encode("test1")  #=> "FCfN80`"
Base85.encode("test1", alphabet: :standard)  #=> "FCfN80`"

# Use Ascii85 alphabet
Base85.encode("test1", alphabet: :ascii85)  #=> "<~FCfN80`~>"

# Use Z85 alphabet
Base85.encode("test1", alphabet: :z85)  #=> "By/Jnf-"

# Use RFC1924 alphabet
Base85.encode("test1", alphabet: :rfc1924)  #=> "bY*jNF#"

To decode a string:

require "base85"

# Use standard alphabet
Base85.decode("ASu!rA7]9")  #=> "encoded"
Base85.decode("ASu!rA7]9", alphabet: :standard)  #=> "encoded"

# Use Ascii85 alphabet
Base85.decode("<~ASu!rA7]9~>", alphabet: :ascii85)  #=> "encoded"
# Special z character
Base85.decode("<~z~>", alphabet: :ascii85)  #=> "\u0000\u0000\u0000\u0000"
# Also accept string without markers
Base85.decode("ASu!rA7]9", alphabet: :ascii85)  #=> "encoded"

# Use Z85 alphabet
Base85.decode("wO#0@wmYo", alphabet: :z85)  #=> "encoded"

# Use RFC1924 alphabet
Base85.decode("Wo~0{WMyO", alphabet: :rfc1924)  #=> "encoded"

Contributing

Bug reports and pull requests are welcome on Codeberg at https://codeberg.org/sd77/base85.

License

The gem is available as open source under the terms of the MIT License.