Loading…

Base64 Encoder Decoder

Base64 shows up anywhere a binary payload has to travel through a text channel - a WebRequest body, a Basic-Auth header, a value stuffed into a global variable or a file that has to stay ASCII-safe. This library covers both the byte-buffer primitives and the string convenience wrappers most code actually calls. The string functions go through StringToCharArray/CharArrayToString with the codepage argument set explicitly to CP_UTF8, not left to the terminal's default ANSI code page. Two terminals running under different Windows locales would otherwise produce different bytes for the same non-ASCII string, which is exactly the kind of bug that only shows up on someone else's machine. Decoding is strict on purpose. Every character is checked against the alphabet, the total length must be a multiple of four, and there can be at most two trailing padding characters - anything else returns false with the output buffer left empty, rather than silently skipping bad characters and returning a plausible-looking but wrong result. A truncated or corrupted Base64 string is a common symptom of a copy/paste mistake in a WebRequest payload; it deserves to fail loudly at the point of decoding, not produce garbage that fails somewhere else, later, for a less obvious reason. Notes and limitations - Only standard Base64 (the '+' and '/' alphabet with '=' padding) is implemented - not the URL-safe variant ('-' and '_'). Translate the two characters before/after if a target system needs URL-safe output. - Decoding treats any character outside the 64-symbol alphabet as an error, including whitespace or line breaks - a Base64 blob copied out of an email or a wrapped text file needs those stripped first. - Base64EncodeString/Base64DecodeToString assume UTF-8 payload text. Binary data that is not meant to be interpreted as text should use the byte buffer functions directly instead of round-tripping through a string.

Script · MT4 · v1.0 · Free

About Base64 Encoder Decoder

Base64 Encoder Decoder is a script for MetaTrader 4. MQL source code included.

Files in the download: Base64.mqh, Base64.txt, Base64Demo.mq4.

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Channels & Envelopes · Binary Options · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria