For generating CRCs
authorBernard Blackham <[email protected]>
Wed, 23 Jun 2004 18:50:36 +0000 (18:50 +0000)
committerBernard Blackham <[email protected]>
Wed, 23 Jun 2004 18:50:36 +0000 (18:50 +0000)
ROM2/crctest.c [new file with mode: 0644]

diff --git a/ROM2/crctest.c b/ROM2/crctest.c
new file mode 100644 (file)
index 0000000..bf48c89
--- /dev/null
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+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 <id> <password> <message>\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;
+}

UCC git Repository :: git.ucc.asn.au