SergeyBel/AES

Getting a wrong output than plain array from DecryptECB with example values

faceslog opened this issue · 2 comments

Hi,

Whenever I try the example with the same values, the DecryptECB output is always different than the initial plain byte array. How should I proceed to decrypt ? Maybe it can be added to the example. Could it be due to my compiler ?

Regards,

Here is my code:

#include <iostream>
#include <vector>

#include "AES.h"

int main()
{
	// ----------------------------  SETUP  -----------------------------
	AES aes(AESKeyLength::AES_128); 
	std::vector<unsigned char> plain = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff }; //plaintext example
	std::vector<unsigned char> key = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; //key example

	std::cout << "[1] Plain: ";
	aes.printHexVector(plain);
	std::cout << std::endl;
	// ------------------------------------------------------------------
	
	
	// ---------------------------- ENCRYPT  ----------------------------
	auto crypted = aes.EncryptECB(plain, key);

	std::cout << "[2] Crypted: ";
	aes.printHexVector(crypted);
	std::cout << std::endl;
	// ------------------------------------------------------------------

	
	// ---------------------------- DECRYPT  ----------------------------
	auto decrypted = aes.DecryptECB(crypted, key);
	
	std::cout << "[3] Decrypted: ";
	aes.printHexVector(decrypted);
	std::cout << std::endl;
	// ------------------------------------------------------------------
	

	return 0;	
}

Here is my output:
output

Oh just figured out it only happen when I use the Debug Mode in Visual Studio Community 2022, in Release mode it works fine.

Was a weird issue with the build config that needed to be updated.

Oh just figured out it only happen when I use the Debug Mode in Visual Studio Community 2022, in Release mode it works fine.