#include "magx_keyGenerator.h"
#include "magx_Decryptor.h"
#include "math.h"
String MeterID="24217303072";
float units=0;
String plainText="";
String cipherText="";
String keyArray[3];
int key;
void setup() {
Serial.begin(9600);
String inp=Input();
key=inp.substring(16).toInt();
cipherText=inp.substring(0,16);
//plainText=Decryption(cipherText,keygen); this was for single DES
// 3DES
plainText=TripleDES_Decryption(cipherText);
String meter=plainText.substring(0,11);
units=float(plainText.substring(11).toInt()/100.0);
if (meter==MeterID){
Serial.println("\t...........Successful Decryption....... ");
Serial.print("meter Number : ");
Serial.println(meter);
Serial.print("Units : ");
Serial.println(units);
}
else{
Serial.println("\t........Rejected, Invalid Token.......... ");
}
}
void loop() {
}
String TripleDES_Decryption(String cipher){
// 3DES KEYS////////////////////////
for (int i=0;i<3;i++){
keyArray[i]=keyGenerated(key);
key=keyArray[i].substring(0,4).toInt();
//Serial.println(keyArray[i]);
}
//////////////////////////////////////
return processDES(processDES(processDES(cipher,keyArray[2],true),keyArray[1],false),keyArray[0],true);
}