30 lines
794 B
C
30 lines
794 B
C
#include <string.h>
|
|
#include <zephyr/device.h>
|
|
#include <errno.h>
|
|
#include <zephyr/sys/util.h>
|
|
#include <zephyr/kernel.h>
|
|
#include <stdint.h>
|
|
|
|
const uint8_t XOR_KEY = 0x5A; // Einfacher, geheimer Schlüssel
|
|
|
|
void xorCrypt(const char *input, char *output, uint8_t key) {
|
|
size_t len = strlen(input);
|
|
for (size_t i = 0; i < len; i++) {
|
|
output[i] = input[i] ^ key;
|
|
}
|
|
output[len] = '\0'; // Null-Terminierung für gültige C-Strings
|
|
}
|
|
|
|
uint16_t computeCRC16(const char *data) {
|
|
uint16_t crc = 0xFFFF;
|
|
for (size_t i = 0; i < strlen(data); i++) {
|
|
crc ^= (uint8_t)data[i] << 8;
|
|
for (int j = 0; j < 8; j++) {
|
|
if (crc & 0x8000)
|
|
crc = (crc << 1) ^ 0x1021;
|
|
else
|
|
crc <<= 1;
|
|
}
|
|
}
|
|
return crc;
|
|
} |