Joseph K. Myers

Monday, April 23, 2002

Base-64, Ordinary Base64 Encoding

Abstract, "binary" data (byte-series) may be preserved as text through the process of "Base64" encoding. This "unix software" is provided as source for very fast algorithmic conversion between raw data (standard 256, i.e. bff) and text (characters A-Za-z0-9+/, i.e. b64).

These programs are designed to work better in doing this job than anything else. Excuse me for my hard-headedness in saying so.

Complaints (otherwise known as features): "b64" and "bff" do not account for either linebreaks (in encoding--normally set at 72 characters/line) or junk characters (in decoding--normally ignored). The b64 program also does not add the useless '=' padding as specified in the "Base64" standard.*

All these caveats are considered features (at least at this writing), and in fact provide greater usability. Base-64 (as I prefer to call it) is *supposed* to be text. As such, other utilities (viewers, etc.) should provide whatever necessary modifications that are necessary. They may do whatever they like; as long as they do not change any _real_ text, and if they make sure to remove their spaces, indentations, and so on before passing the data to bff, it all works--fast and perfect. This is the real magic of Base-64.

*(I wish. Actually, they do--except for putting in linebreaks, which I can't swallow--although I consider these functions outrageous. Still though, whoever wanted '=' padding was a capital idiot. Oh, by the way: I hate CRLF; I love LF!)

Download the source (with no "help" files; you are expected to save these "instructions"), base-64.tar.gz (712 bytes).

Usage is as follows:

b64 [< input] [> output]

bff [< input] [> output]

Without these flags, the programs default to "read from standard input and write to standard output."

Building (or "make"ing) can be gone with the usual 'make' command (although not necessary, a simple "Makefile" is included for this purpose). The necessary command is simply 'gcc -O3 b64.c -o b64' (and the same for bff).

Installation should be done manually by moving the completed programs (b64, bff) into /usr/local/bin and setting them to be executable by all (something like 'chmod 755'--if this wasn't done automatically).

Performance is about 10 MB/sec for encode/decode on my present (low-end) system. Other computers I've tried work faster (my server gets almost three times that figure).

Cool times/records:

1 MB encode (old style): 0.008 sec. (sweet!)

1 MB encode/decode: 0.069 sec.

http://www.myersdaily.org/joseph/unix/base-64.txt