For Arduino
Updated: spaniakos 2015
This example dempnstrates how to implement:
-
3des Encryption
-
3des Decyption
-
Padding check
Using all functions manually.
#include <DES.h>
#include "./printf.h"
unsigned long ms;
void setup() {
Serial.begin(9600);
delay(100);
printf_begin();
delay(100);
printf("\n============================================\n");
printf(" Triple DES sample for Arduino/Raspberry pi\n");
printf("============================================\n");
des.
init(
"012345677654321001234567\0",(
unsigned long long int)0);
}
void loop() {
ms = micros();
byte plaintext[] = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
printf(" Encryption took %lu micros\n",(micros() - ms));
ms = micros();
bool ok = des.
CheckPad(plaintext_p,
sizeof(plaintext_p));
if (ok)
printf("padding ok!");
else
printf("padding corrupted!");
printf(" Decryption took %lu micros",(micros() - ms));
delay(2000);
}