String Encryption for Uno (ATMega328)

Hi All,

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!

Thanks,

Dauhee.

Maybe a simpler encryption will work? what is the purpose of encrypting strings in your project?

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!

Thanks.

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!

Thanks.

XOR used with a one-time key pad is unbreakable.

Lefty

I have tried existing libraries without success

You haven't said what failed. Why not post some code which demonstrates the problem?

Pete

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 :frowning:

#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"));
  }
}

This is using the AES library under:
http://arduino.cc/forum/index.php/topic,88890.0.html

And additional help from:
http://arduino.cc/forum/index.php/topic,96197.0.html

Any assistance would help minimise my hair loss :slight_smile:

Moderator edit: session ID removed from link.