liudr
Your example worked right out of the box XD
As predicted mine did not ]
So I did some code changes. I reintroduced avr/pgmspace.h because it declares many types I use regularly.
I also created a class called ConsoleSerial that I mapped on Serial Serial1 Serial2 and Serial3. This class can not read data (it wil say the buffer is empty) but it dumps all the Serial.prints to the stdout 8)
I added String and some other stuff.
My AES test sketch works now on PC 8) (only some extra includes were needed) It is a perfect example of why you would use this code. There is no Arduino specifics in doing AES encryption.
The sketch needs the unmodified AES library (http://arduino.cc/forum/index.php/topic,88890.0.html) and your updated code (attached) and the sketch code (below).
Works great. Thank you.
Back to you to say it ain't working on your side 8)
Best regards
Jan
#include <Arduino.h>
#include <LiquidCrystal.h>
#include <cstdlib>
#include <iostream>
#include <windows.h>
#include "AES.h"
using namespace std;
#define KEYLENGTH 32
AES aes;
char PassString[] = "This is hard to believe but true however";// this must be at least KEYLENGTH characters long
byte key[KEYLENGTH];
void setup()
{
Serial.begin(115200);
Serial.println("Starting AES test");
for (int i = 0; i < KEYLENGTH; i++)
{
key[i] = PassString[i];
}
if (aes.set_key(key, KEYLENGTH) != 0)
{
Serial.println(F("Failed to set key"));
}
}
// The loop function is called in an endless loop
void loop()
{
char Message[] = "A top secret message. 123456789012345678901234";
byte plain[N_BLOCK];
byte cipher[N_BLOCK];
byte decrypted[N_BLOCK];
Serial.print(F("message : '"));
Serial.print(Message);
Serial.println(F("'"));
Serial.print(F("plain binary: '"));
for (int i = 0; i < N_BLOCK; i++)
{
plain[i] = Message[i];
cipher[i] = 0;
decrypted[i] = 0;
Serial.print(plain[i]);
}
Serial.println(F("'"));
Serial.print(F("plain char: '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(char(plain[i]));
}
Serial.println(F("'"));
if (aes.encrypt(plain, cipher) == 0)
{
Serial.print(F("encrypted : '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(cipher[i]);
}
Serial.println(F("'"));
Serial.print(F("encrypted hex : '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(cipher[i],HEX);
}
Serial.println(F("'"));
Serial.print(F("encrypted char: '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(char(cipher[i]));
}
Serial.println(F("'"));
} else
{
Serial.println(F("Failed to encrypt"));
}
if (aes.decrypt(cipher, decrypted) == 0)
{
Serial.print(F("decrypted binary : '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(decrypted[i]);
}
Serial.println(F("'"));
Serial.print(F("decrypted char : '"));
for (int i = 0; i < N_BLOCK; i++)
{
Serial.print(char(decrypted[i]));
}
Serial.println(F("'"));
} else
{
Serial.println(F("Failed to decrypt"));
}
delay(1000);
}
arduino.zip (23.3 KB)