All predicatesShow -- Base64 encoding and decoding

Prolog-based base64 encoding using DCG rules. Encoding according to rfc2045. For example:

1 ?- base64('Hello World', X).
X = 'SGVsbG8gV29ybGQ='.

2 ?- base64(H, 'SGVsbG8gV29ybGQ=').
H = 'Hello World'.

The Base64URL encoding provides a URL and file name friendly alternative to base64. Base64URL encoded strings do not contain white space.

- Base64 only works with bytes. The grammars do not check the input to be in the range 0..255.
To be done
- Stream I/O
- White-space introduction and parsing
- Encoding support (notably UTF-8)
Source base64_encoded(+Plain, -Encoded, +Options) is det
base64_encoded(-Plain, +Encoded, +Options) is det
General the base64 encoding and decoding. This predicate subsumes base64/2 and base64url/2, providing control over padding, the characters used for encoding and the output type. Options:
Define the encoding character set to use. The (default) classic uses the classical rfc2045 characters. The value url uses URL and file name friendly characters. See base64url/2. The value openbsd uses the OpenBSD password-file alphabet.
If true (default), the output is padded with = characters.
Defines the type of the output. One of string (default) or atom.
Encoding to use for translation between (Unicode) text and bytes (Base64 is an encoding for bytes). Default is utf8.
Plain- is an atom or string containing the unencoded (plain) text.
Encoded- is an atom or string containing the base64 encoded version of Plain.
Source base64(+Plain, -Encoded) is det
base64(-Plain, +Encoded) is det
Equivalent to base64_encoded/3 using the options as(atom) and encoding(iso_latin_1).
- New code should use base64_encoded/3. Notably the iso_latin_1 should be utf8 in most today's applications.
Source base64url(+Plain, -Encoded) is det
base64url(-Plain, +Encoded) is det
Translates between plaintext and base64url encoded atom or string. Base64URL encoded values can safely be used as URLs and file names. The use "-" instead of "+", "_" instead of "/" and do not use padding. This implies that the encoded value cannot be embedded inside a longer string.

Equivalent to base64_encoded/3 using the options as(atom), encoding(utf8) and charset(url).

Source base64_encoded(+PlainText, +Options)// is det
base64_encoded(-PlainText, +Options)// is det
Source base64(+PlainText)// is det
base64(-PlainText)// is det
Encode/decode list of character codes using base64. See also base64/2.
Source base64url(+PlainText)// is det
base64url(-PlainText)// is det
Encode/decode list of character codes using Base64URL. See also base64url/2.
Source encode(+Padded, +PlainText, +Charset)//[private]
Source decode(+Padded, -PlainText, +Charset)//[private]