From: Bernard Blackham Date: Wed, 23 Jun 2004 18:50:36 +0000 (+0000) Subject: For generating CRCs X-Git-Tag: ROMW~7 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9203e74dcb42e84ba084914724b48cfac402c9b5;p=uccvend-snackrom.git For generating CRCs --- diff --git a/ROM2/crctest.c b/ROM2/crctest.c new file mode 100644 index 0000000..bf48c89 --- /dev/null +++ b/ROM2/crctest.c @@ -0,0 +1,41 @@ +#include +#include +typedef unsigned short u16; +typedef unsigned char bool; +#include "crctab.h" + +unsigned short +docrc (unsigned char *p, int len, bool pad, unsigned short crcstart) +{ + int len2 = len; + unsigned short crc = crcstart; + + while (len-- > 0) + crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++]; + if (pad && len2 < 128) { + len = 128-len; + while (len-- > 0) + crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a]; + } + + return crc; +} + +int main(int argc, char** argv) { + unsigned short crc; + unsigned short msgid; + char *password, *message; + if (argc != 4) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return 1; + } + msgid = strtol(argv[1], NULL, 16); + password = argv[2]; + message = argv[3]; + crc = docrc(((char*)&msgid)+1, 1, 0, 0); + crc = docrc(((char*)&msgid), 1, 0, crc); + crc = docrc(password, strlen(password), 0, crc); + crc = docrc(message, strlen(message), 0, crc); + printf("CRC is 0x%x\n", crc); + return 0; +}