CryptoByLeo/Src/Simetric/ChaCha20/Test.mq5
2026-08-12 13:31:16 -05:00

59 lines
1.8 KiB
MQL5

//+------------------------------------------------------------------+
//| Test.mq5 |
//| Copyright 2026, Niquel Mendoza |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2026, Niquel Mendoza"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#include "Main.mqh"
#include "..\\..\\Utils\\Main.mqh"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
uchar data[];
ArrayResize(data, 4);
data[0] = 'h';
data[1] = 'o';
data[2] = 'l';
data[3] = 'a';
//---
TSN::CChaCha20 cipher;
uchar key[CHACHA20_KEYSIZEB] =
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
};
uchar iv[CHACHA20_IVNONE_B] =
{
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11
};
// cifrado
cipher.Init(key, iv, 0);
cipher.XProcces(data, 4);
string out = "";
TSN::CEncrptUtils::ToHexUpper(data, out);
Print("Cifrado: ");
Print(out);
// descifrado
cipher.Init(key, iv, 0);
cipher.XProcces(data, 4);
Print("DesCifrado: ");
Print(CharArrayToString(data));
}
//+------------------------------------------------------------------+