I have declared a struct with some variables that right now are fixed, but one of the variables on the struct needs to be what the Arduino's serial port reads.
struct testing_var
{
const char *name;
byte key[32];
byte pt[16];
};
static testing_var const test1 = {
.name = "Speck-128-ECB",
.key = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},
.pt = {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20},
};
As you can see for how I have declared it, I'm trying to get a plaintext from the serial port and the Arduino should encrypt that. I have a function that does this encryption, but I can't quite figure out how to pass what the serial port reads to the struct.
void loop() {
if (Serial.available()>0) {
var1 = Serial.read();
}
I need to pass this var1 as the variable pt in the struct. Any clues? I'm maybe missing something very obvious, but I don't usually work with structs.
EDIT: I'm trying to assign the value read by the serial port to the struct by creating another function that goes like this:
void setPlain(struct PlainText *myPlain, const char* thePlain){
myPlain -> plaintext = the Plain;
}
Then, in the loop, I use:
if (Serial.available()>0) {
var1 = Serial.read();
setPlain(&PlainText, var1)
}
I'm getting an error using this function, I guess that it has something to do with the type of variable I'm trying to assign, these values are in HEX, not in char. But I'm not really sure it that's it or what other workaround should I use.