#include #include #include #define BLOCK_SIZE 16 static uint8_t compute_xor_checksum(const uint8_t *block, size_t n) { uint8_t cs = 0; for (size_t i = 0; i < n; ++i) { cs ^= block[i]; } return cs; } int main(void) { uint8_t block[BLOCK_SIZE]; const char *msg = "Hello OSTEP!"; memset(block, 0, BLOCK_SIZE); strncpy((char *)block, msg, BLOCK_SIZE - 1); uint8_t stored_cs = compute_xor_checksum(block, BLOCK_SIZE); printf("Stored data: %s\n", (char *)block); printf("Stored checksum: 0x%02X\n", stored_cs); block[3] ^= 0x01; /* silent corruption */ uint8_t read_cs = compute_xor_checksum(block, BLOCK_SIZE); printf("Read checksum: 0x%02X\n", read_cs); if (read_cs != stored_cs) { printf("Corruption detected! Data integrity violated.\n"); } else { printf("Checksums match.\n"); } return 0; }