Advertisement
TCB13

gencode.c | STKeys, calculate checksum byte of serial number

Jul 11th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.19 KB | None | 0 0
  1. /*
  2.     Author: Kevin Devine <wyse101 0x40 gmail.com>
  3.     WWW:    http://weiss.u40.hosting.digiweb.ie/
  4.     Date:   April 2008
  5.  
  6.     used to calculate checksum byte of serial number for Thomson router
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. typedef unsigned int u32;
  13. typedef unsigned char u8;
  14.  
  15. u8 numTable[256+1];
  16.  
  17. void createTable(u8 initVal)
  18. {
  19.     u32 i,j;
  20.     u8 x,y;
  21.  
  22.     if(numTable[256] != initVal) {
  23.  
  24.       numTable[256] = initVal;
  25.  
  26.       for(i = 0;i < 256;i++) {
  27.  
  28.         x = i;
  29.  
  30.         for(j = 0;j < 8;j++) {
  31.  
  32.           y = (x >> 7);
  33.           x <<= 1;
  34.  
  35.           if( y & y )
  36.               x ^= numTable[256];
  37.         }
  38.         numTable[i] = x;
  39.       }
  40.     }
  41. }
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.     u8 sumCode = 0,*p;
  46.  
  47.     if(--argc && (strlen(argv[1])) == 9) {
  48.       createTable(7);
  49.  
  50.       for(p = argv[1];*p = toupper(*p);p++)
  51.         sumCode = numTable[ (sumCode ^ *p) ] ^ (sumCode << 8);
  52.  
  53.         /* note: this is more like a checksum than configuration code */
  54.       fprintf(stdout,"\nSpeedTouch [C]hecksum [C]ode: ( %.2x )\n\n",sumCode);
  55.     } else
  56.       fprintf(stdout,"\n%s <SERIAL NUMBER>\n\n",argv[0]);
  57.     return(0);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement