#include #include #include "crc32tab.h" /* * Calculates CRC * * Copyright (c) 2022 - 2023 R.J. van der Putten, Leiden, Holland, * rob at sput dot nl. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as * published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ int main(void) { char line[4096]; unsigned char t; int i, len; unsigned int r; i = 0; len = 0; r = 0; t = 0; memset(line, 0, 4096); while (fgets(line, 4080, stdin)) { i = 0; r = 0xFFFFFFFF; /* Cleanup */ len = strlen(line) - 1; if (line[len] == 10) { line[len] = 0; len--; } if (line[len] == 13) { line[len] = 0; len--; } len++; /* Pad for length of CRC */ line[len] = 0; len++; line[len] = 0; len++; line[len] = 0; len++; line[len] = 0; len++; while (i < len) { /* Shift CRC width - 8 */ t = (char) ((r >> 24) & 0xFF); r = (r << 8) | (unsigned char) line[i]; r ^= crctab[t]; i++; } printf("Crc: %08X\n", r); } return(0); }