Computer Interfacing
Discussions about interfacing and electronics
 

CRC or Hash


 

       Computer Interfacing Forum Index -> General serial
Author Message
Guest








Oct 15, 2010 11:36 am

I have to detect data in a RS232 communication where the packet are suppose to be protected with a a crc with this code:

Code:
word crc_gen(byte *p, byte first, byte last)
{
#define MASK    0x0101          /* crc-ccitt mask */
word crc,ch;
byte i,k;
    crc=0;
    for (i=first; i<=last; i++) {
         ch =p[i];
         ch <<= 8;
         for (k=0; k<8; k++) {
              if ((crc^ch) & 0x8000)  crc = (crc << 1)^MASK;
               else crc <<= 1;
              ch <<= 1;
          }
     }
     return(crc);
}


I sniffed some packets but I can't match any result, using this code.
I guess it could be a different protection like a Hash but I'm not sure.
Is it possible to have some help?
The data sniffed are:

example 1

byte1: 30
byte2: 00
byte3: 00
byte4: 00
byte5: 00
byte6: 00
byte7: 00
byte8: 00
byte9: 00
byte10: 00
byte11: 00
byte12: 24
byte13: 25
byte14: 25
byte15: FF
byte16: F0
byte17: 7D

Code:
sniffed crc1: 5B        my calculation: crc 1: 83
        crc2: 43                        crc 2: BD

example 2

byte1: 54
byte2: 00
byte3: 00
byte4: 00
byte5: 00
byte6: 00
byte7: 00
byte8: 00
byte9: 00
byte10: 00
byte11: 00
byte12: 91
byte13: 4A
byte14: 40
byte15: 9C
byte16: F0
byte17: F5

Code:
sniffed crc1: 0F my calculation: crc 1: B8
        crc2: 6C                 crc 2: 5B

       Computer Interfacing Forum Index -> General serial
Page 1 of 1



Running on php BB © 2001, 2009 php BB Group
   Lammert Bies     Interfacing     Sitemap     Forum