#include <EEPROM.h>
// decode_bpsk_data
// INPUT/OUTPUT VALUES
// RAW DATA (DEC) 248, 84, 254, 82, 38, 194
// MIRRORED RAW DATA (DEC) 31, 42, 127, 74, 100, 67
// OUTPUT DATA BYTES [11, 2, 20, 26, 0, 59] key = 20
unsigned char b0 = 248; // raw data bytes
unsigned char b1 = 84;
unsigned char b2 = 254;
unsigned char b3 = 82;
unsigned char b4 = 38;
unsigned char b5 = 194;
unsigned char bm0; // mirror raw data bytes
unsigned char bm1;
unsigned char bm2;
unsigned char bm3;
unsigned char bm4;
unsigned char bm5;
unsigned char out0; // ??
unsigned char out1; // command (should be 2)
unsigned char out2; // key
unsigned char out3; // sekce
unsigned char out4; // checksum
unsigned char out5; // append???
unsigned char sekce;
unsigned char command;
unsigned char master_key = 107; //master key
unsigned char key; // vypocitany key po mirroru b2
int s1 = 8; // port zapnuti sekce
int in = 0; // cteni hodnot
int address = 0; // adresa v eeprom kde je ulozeno cislo sekce
byte value = 26; // hodnota eeprom
int val;
void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
attachInterrupt(0, hrana, RISING); //
/*byte value = EEPROM.read(address);
Serial.print("Hodnota na adrese ");
Serial.print(address);
Serial.print(": ");
Serial.println(value);
//digitalWrite(s1, HIGH);*/
}
void loop()
{
bm0 = (b0 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
bm1 = (b1 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
bm2 = (b2 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
bm3 = (b3 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
bm4 = (b4 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
bm5 = (b5 * 0x0202020202ULL & 0x010884422010ULL) % 1023;
key = bm2 ^ 107; // vypocet key (mirror byte2 XOR master_key)
// god know what
out0 = bm0 ^ (key);
Serial.print("GKW = ");
Serial.print(out0);
Serial.println();
// cpmmand
out1 = bm1 ^ (2*key);
Serial.print("command = ");
Serial.print(out1);
Serial.println();
// key
Serial.print("key = ");
Serial.print(key);
Serial.println();
// sekce
out3 = bm3 ^ (4*key);
Serial.print("sekce = ");
Serial.print(out3);
Serial.println();
if (out3 == value)
{ // tests if x is equal to y
digitalWrite(s1, HIGH);
}
//checksum
out4 = bm4 ^ (5*key);
Serial.print("checksum = ");
Serial.print(out4);
Serial.println();
//append
out5 = bm5 ^ (6*key);
Serial.print("append = ");
Serial.print(out5);
Serial.println();
Serial.println();
Serial.println();
for (;;) { /* empty */ } //infinte loop
delay(1000);
}
void hrana()
{
delay(400);
val = digitalRead(in);
Serial.print(val);
}