blob: 175ab5078703b904f4693b535127e0c5a92ea891 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#define DATA_LEN 252
#define DIVISOR 0x04C11DB7
int main() {
uint8_t data[DATA_LEN];
read(STDIN_FILENO, data, DATA_LEN);
uint32_t crc = 0xFFFFFFFF;
for (size_t i = 0; i < DATA_LEN; i++) {
crc ^= data[i] << 24;
for (uint8_t j = 0; j < 8; j++) {
uint8_t nskip = crc >> 31;
crc <<= 1;
if (nskip) crc ^= DIVISOR;
}
}
write(STDOUT_FILENO, (uint8_t *) &crc, 4);
return 0;
}
|