++ed by:
1 non-PAUSE user
Author image John Gamble

NAME

Convert::Base85 - Encoding and decoding to and from Base 85 strings

SYNOPSIS

    use Convert::Base85;
 
    my $encoded = Convert::Base85::encode($data);
    my $decoded = Convert::Base85::decode($encoded);

or

    use Convert::Base85 qw(base85_encode base85_decode);
 
    my $encoded = base85_encode($data);
    my $decoded = base85_decode($encoded);

DESCRIPTION

This module implements a Base85 conversion for encoding binary data as text. This is done by interpreting each group of sixteen bytes as a 128-bit integer, which is then converted to a twenty-digit base 85 representation using the alphanumeric characters 0-9, A-Z, and a-z, in addition to the punctuation characters !, #, $, %, &, (, ), *, +, -, ;, <, =, >, ?, @, ^, _, `, {, |, }, and ~, in that order.

This creates a string that is five fourths (1.25) larger than the original data, making it more efficient than MIME::Base64's 3-to-4 ratio (1.3333).

As noted above, the conversion makes use of 128-bit arithmatic, which most computers can't handle natively, which is why the module Math::Int128 needs to be installed as well.

FUNCTIONS

base85_check

Examine a string for characters that fall outside the Base 85 character set.

Returns the first character position that fails the test, or -1 if no characters fail.

    if (my $d = base85_check($base85str) >= 0)
    {
        carp "Incorrect character at position $d; cannot decode input string";
        return undef;
    }

base85_encode

Convert::Base85::encode

Converts input data to Base85 test.

This function may be exported as base85_encode into the caller's namespace.

   my $datalen = length($data);
   my $encoded = base85_encode($data); 

Or, if you want to have managable lines, read 48 bytes at a time and write 60-character lines (remembering that encode() takes 16 bytes at a time and encodes to 20 bytes). Remember to save the original length in case the data had to be padded out to a multiple of 16.

base85_decode

Convert::Base85::decode

Converts the Base85-encoded string back to bytes. Any spaces, linebreaks, or other whitespace are stripped from the string before decoding.

This function may be exported as base85_decode into the caller's namespace.

If your original data wasn't an even multiple of sixteen in length, the decoded data may have some padding with null bytes ('\0'), which can be removed.

    #
    # Decode the string and compare its length with the length of the original data.
    #
    my $decoded = base85_decode($data); 
    my $padding = length($decoded) - $datalen;
    chop $decoded while ($padding-- > 0);

SEE ALSO

The Base85 Character Set

The Base85 character set is described by Robert Elz in his RFC1924 of April 1st 1996, "A Compact Representation of IPv6 Addresses" which are made up from the 94 printable ASCII characters, minus quote marks, comma, slash and backslash, and the brackets.

Despite it being an April Fool's Day RFC, the reasoning for the choice of characters for the set was solid.

The character set is:

    '0'..'9', 'A'..'Z', 'a'..'z', '!', '#', '$', '%', '&',
    '*', '+', '-', ';', '<', '=', '>', '?', '@', '^', '_',
    '`', '|', and '~'.

and allows for the possibility of using the string in a MIME container.

Ascii85

Base85 is similar in concept to Ascii85, a format developed for the btoa program, and later adopted with changes by Adobe for Postscript's ASCII85Encode filter. There are, of course, modules on CPAN that provide this format.

Base64

Base64 encoding is an eight-bit to six-bit encoding scheme that, depending on the characters used for encoding, has been used for uuencode and MIME transfer, among many other formats. There are, of course, modules on CPAN that provide this format.

AUTHOR

John M. Gamble <jgamble at cpan.org>

BUGS

Please report any bugs or feature requests to bug-convert-base85 at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Convert-Base85. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

This module is on Github at https://github.com/jgamble/Convert-Base85.

You can also look for information on MetaCPAN.

LICENSE AND COPYRIGHT

Copyright (c) 2019 John M. Gamble.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

1;

__END__