I have tried unsuccessfully to perform string encryption. My grasp of the C language is not good. I have tried existing libraries without success, such as skipjack from avr-crypto, and also AES from another source.
If anybody was able to provide some assistance, I would be much appreciative!
dauhee:
It is for transmission over virtualwire between arduino units. I had looked at XOR but its very weak. XTEA, SKipjack, DES, AES, anything will do!
if there was example code for XOR one time pad that would be fantastic!
The code I have been working with is as below. It only works for N_BLOCK chars which is 16. Any chars after that are ignored and don't get encrypted. I've tried to use multi-dimentional byte arrays and its getting ugly
#include <AES.h>
AES aes ;
void loop ()
{
}
void setup ()
{
Serial.begin (57600) ;
const int KEYLENGTH = 32;
char PassString[] = "This is hard to believe but true however";// this must be at least KEYLENGTH characters long
byte key[KEYLENGTH];
char Message[] = "A top secret message. 123456789012345678901234";
byte plain[strlen(Message)];
byte cipher[strlen(Message)];
byte decrypted[strlen(Message)];
String strData = "";
Serial.println("Starting AES test");
for (int i = 0; i < KEYLENGTH; i++)
{
key[i] = PassString[i];
}
for (int i = 0; i < strlen(Message); i++)
{
plain[i] = Message[i];
cipher[i] = 0;
decrypted[i] = 0;
}
if (aes.set_key(key, KEYLENGTH) != 0)
{
Serial.println(F("Failed to set key"));
}
for (int a = 0; a < (int)ceil((float)strlen(Message)/(float)N_BLOCK); a++)
{
//Serial.println(a);
}
if (aes.encrypt(plain, cipher) == 0)
{
Serial.print(F("encrypted char: '"));
for (int i = 0; i < strlen(Message); 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 char : '"));
for (int i = 0; i < strlen(Message); i++)
{
Serial.print(char(decrypted[i]));
}
Serial.println(F("'"));
}
else
{
Serial.println(F("Failed to decrypt"));
}
}