CryptoByLeo/Src/Simetric/AES/Test.mq5

83 lines
2.4 KiB
MQL5
Raw Permalink Normal View History

2026-08-10 16:05:10 -05:00
//+------------------------------------------------------------------+
//| 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"
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
uchar key[32] =
{
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 buf[16] =
{
0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a
};
uchar copia2[16];
ArrayCopy(copia2, buf, 0, 0, 16);
//--- Inicializamos AES-256
TSN::CAes ae;
ae.Method(TSN::AES_CRYPTH_256);
//---
if(!ae.Init(key))
{
Print("Error al inicializar AES");
return;
}
//--- Test 2.
2026-08-11 18:00:24 -05:00
ulong dummy = 0;
2026-08-10 16:05:10 -05:00
ulong a = GetMicrosecondCount();
2026-08-11 18:00:24 -05:00
for(int i = 0; i < 100000; i++)
2026-08-10 16:05:10 -05:00
{
CryptEncode(CRYPT_AES256, copia2, key, copia2);
2026-08-11 18:00:24 -05:00
dummy += copia2[0];
2026-08-10 16:05:10 -05:00
}
ulong b = GetMicrosecondCount();
2026-08-11 18:00:24 -05:00
Print("Tiempo = ", (b - a), " dummy: ", dummy);
2026-08-10 16:05:10 -05:00
//--- Test 1.
2026-08-11 18:00:24 -05:00
dummy = 0;
2026-08-10 16:05:10 -05:00
a = GetMicrosecondCount();
2026-08-11 18:00:24 -05:00
for(int i = 0; i < 100000; i++)
2026-08-10 16:05:10 -05:00
{
ae.Cifrar(buf);
2026-08-11 18:00:24 -05:00
dummy += buf[0];
2026-08-10 16:05:10 -05:00
}
b = GetMicrosecondCount();
2026-08-11 18:00:24 -05:00
Print("Tiempo = ", (b - a), " dummy: ", dummy);
2026-08-10 16:05:10 -05:00
//---
a = GetMicrosecondCount();
2026-08-12 08:29:06 -05:00
for(int i = 0; i < 100000; i++)
2026-08-10 16:05:10 -05:00
ae.KeyExpansion(key); // esto SÍ rehace el KeyExpansion cada vez
b = GetMicrosecondCount();
2026-08-12 08:29:06 -05:00
Print("Solo Init (con KeyExpansion) 100000 = ", (b - a));
2026-08-10 16:05:10 -05:00
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+