I found this a while back not sure if it was originally written in c or c++... been trying to convert it to work with Arduino. I am just trying to make this bit work and will add some more in the future.
I keep getting the error: invalid types 'char[int]' for array subscript on this line " encrypted += original[temp] ^ (int(key) + temp) % 255;"
char original = 'put me in a box, a box of worms';
char key = 'z';
char end;
char getKey;
int temp = 0;
String encrypted = "";
String unencrypt = "";
void setup(){
Serial.begin(9600);
end = original ^ key;
getKey = original ^ end;
Serial.println("Ready");
delay(1000);
}
void loop(){
Serial.print(original);
c();
delay(1000);
d();
delay(5000);
}
void c(){// add variable in future
temp = 0;
while(temp < sizeof(original)){
encrypted += original[temp] ^ (int(key) + temp) % 255;
temp++;
}
Serial.print("Encrypt: ");
Serial.println(encrypted);
}
void d(){
temp = 0;
while(temp < sizeof(original)){
unencrypt += encrypted[temp] ^ (int(key) + temp) % 255;
temp++;
}
Serial.print("Decrypt: ");
Serial.println(unencrypt);
}