world.Base64Encode

MUSHclient script function (Method) — introduced in version 3.22

Encodes a string using base-64 encoding.

Prototype

VARIANT Base64Encode(BSTR Text, BOOL MultiLine);

Data type meanings

Description

Encodes a string (like "swordfish") returning it as base-64 characters (eg. "c3dvcmRmaXNo").

Each 3 characters of input become 4 characters of output. This can be used:

a) as a primitive form of encryption (or 'information hiding')
b) to send non-printable characters as a text stream

Note that due to the way strings are represented internally, it is not possible for the encoded string to contain the NULL character (hex 0x00) and be returned correctly, however see below for a work-around for Lua.

If "multiline" is true, then the returned string will have a carriage-return/linefeed after every 76 characters, otherwise it will be one long text stream.

VBscript example

world.note world.base64encode ("swordfish", 0)

Jscript example

world.note (world.base64encode ("swordfish", 0));

PerlScript example

$world->note ($world->base64encode ("swordfish", 0));

Python example

world.note (world.base64encode ("swordfish", 0))

Lua example

Note (Base64Encode ("swordfish", 0))

Lua notes

The multi-line flag is optional, and defaults to false.

---

In MUSHclient version 3.57 onwards you can also use

encoded_string = utils.base64encode (s, [, linebreaks] )

This works the same as described above, however it will correctly handle strings with the null (hex 00) character in them.

Return value

The encoded string.

Related topic

Utilities

See also

FunctionDescription
Base64DecodeTakes a base-64 encoded string and decodes it.