#include <cstring>
#include <stdio.h>
#include <Wire.h>
#define EEPROM_I2C_ADDRESS 0x50
byte eeprom_read_byte(uint8_t i2c_device_address, uint16_t eeprom_data_address) {
uint8_t rdata = 0xFF;
Wire.beginTransmission(i2c_device_address);
Wire.write((uint8_t)(eeprom_data_address >> 8)); //writes the MSB
Wire.write((uint8_t)(eeprom_data_address & 0xFF)); //writes the LSB
Wire.endTransmission();
Wire.requestFrom(i2c_device_address,(uint8_t)1);
if (Wire.available()) {
rdata = Wire.read();
}
return rdata;
}
String eeprom_read_string(uint16_t eeprom_data_address, unsigned int size) {
String result;
result.reserve(size);
for (unsigned int i = 0; i < size; ++i) {
result.concat((char)eeprom_read_byte(EEPROM_I2C_ADDRESS, i + eeprom_data_address));
}
return result;
}
void xor_str(String& str, String& key) {
int str_len = 17;
int key_len = key.length();
String result = "";
for (int i = 0; i < str_len; i++) {
result += (char)(str.charAt(i) ^ key.charAt(i % key_len));
}
str = result;
}
void setup()
{
Serial1.begin(9600);
Wire.begin();
String key = eeprom_read_string(0x1337, 23);
String flag = "\x05\x03\x0f\x13\x29\x07\x09\x13\x05\x1c\x19\x13\x07\x1a\x07\x08\x13";
xor_str(flag, key);
}
void loop()
{
if (Serial1.available()) { // Check if there's data available on the serial port
String input = Serial1.readStringUntil('\n'); // Read the string from the serial port
Serial1.println(input);
if (input == "secret_value") { // Compare the input string to the secret value
Serial1.println("Success!"); // Print "Success!" to the serial monitor
}
else {
Serial1.println("Wrong!");
}
}
}