Libraries: Base64 Class

 

Base64 Class:

//|This a library for a quick and easy encryption and decryption using //|base64. The usage is very simple and can be done in a few lines of //|code. <<< //|The return value of a method is the required output. <<< //|Feel free to use this library at your convenience.If it is //|helpful, please reward me by rating this item on mql5 site. //| >>From a developer, for developers.<<

Author: Nelson Wanyama

 
/**
 * Base 64 is an encoding scheme that converts binary data into text
 * format so that encoded textual data can be easily transported over
 * network un-corrupted and without any data loss. Base64 is used
 * commonly in a number of applications including email via MIME, and
 * storing complex data in XML.
 */
string StringEncodeBase64(const string text)
{
        uchar src[], dst[], key[];

        StringToCharArray("", key, 0, StringLen(""));
        StringToCharArray(text, src, 0, StringLen(text));

        //--- encode src[] with BASE64
        int res = CryptEncode(CRYPT_BASE64, src, key, dst);

        return (res > 0) ? CharArrayToString(dst) : "";
}

string StringDecodeBase64(const string text)
{
        uchar src[], dst[], key[];

        StringToCharArray("", key, 0, StringLen(""));
        StringToCharArray(text, src, 0, StringLen(text));

        //--- decode src[] with BASE64
        int res = CryptDecode(CRYPT_BASE64, src, key, dst);

        return (res > 0) ? CharArrayToString(dst) : "";
}
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
    {
     string input_string = " Copyright 2020,Anonymous3.";
     string encoded = StringEncodeBase64(input_string);
     string decoded = StringDecodeBase64(encoded);
//---
     Print("Encoded = ", encoded);
     Print("Decoded = ", decoded);
//---
    }
//+------------------------------------------------------------------+
 
amrali:

Good. Now it's a two-line library.

Reason: