A Wolfram Mathematica base64 package

The base64 package allows for handling base64 encoding and decoding within Wolfram Mathematica (version 5.1 or higher).

Install instructions

The software is available on GitHub, and is installed as follows.

  1. Clone the base64 repository locally.
  2. Copy the file base64.m according to the following table, depending on the operating system you use and your preference for a user-based or a system-wide installation.
    OS User-based installation System-wide installation
    Mac OS X ~/Library/Mathematica/Applications /Library/Mathematica/Applications
    Linux ~/.Mathematica/Applications R/AddOns/Applications
    Windows ~/Applications Data/Mathematica/Applications R/AddOns/Applications
    In the table ~ denotes the user's home directory in Mac OS X and Linux and the user's directory inside Documents and Settings in Windows, while R denotes the Mathematica root directory.
    Note If you like the non-standard way, saving the package file in any directory contained in Mathematica's $Path variable will also work.
  3. Read the user manual notebook base64-usage.nb.

Using the package

The package is loaded as usual:

In[1]:= <<base64`

The functions base64Encode and base64Decode are provided: the first one handles encoding a succession of bytes (contained in a list):

In[2]:= ?base64Encode
base64Encode[byt] returns the string base64-encoding the sequence of bytes byt

In[3]:= original=ToCharacterCode["The quick brown fox jumps over the lazy dog"];
In[4]:= base64Encode[original]
Out[4]= VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==

Analogously, base64Decode returns a list containing the decoded bits corresponding to a base64 encoded string:

In[5]:= ?base64Decode
base64Decode[str] returns the list containing the bits corresponding to the base64-decoded version of the string str

In[6]:= decodedBytes=base64Decode["VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw=="];
In[7]:= FromCharacterCode[decodedBytes]
Out[7]= The quick brown fox jumps over the lazy dog


base64 is licensed uder the LGPL license.