Files : crc.cpp
DesignBy: Xu Chen.
UpdateBy: Xiao chengsheng Date: 1999.9.16
This program is secure module of host
\*****************************************************/
//#define CRC_TEST
#ifndef _CRC__
#define _CRC__
unsigned short crcCreate(unsigned short Length, char * TextPtr, unsigned short
crc_start);
#endif
typedef unsigned short WORD;
typedef unsigned char BYTE;
//static WORD crc_table[16];
static const WORD crc_table[16]=
{
0x0000, 0x1081, 0x2102, 0x3183,
0x4204, 0x5285, 0x6306, 0x7387,
0x8408, 0x9489, 0xA50A, 0xB58B,
0xC60C, 0xD68D, 0xE70E, 0xF78F
};
WORD crcCreate(WORD Length, char * TextPtr, WORD crc_start)
{
BYTE TempChar;
WORD i, index, CRCTemp;
CRCTemp = crc_start; // CRC-CCITT preconditioning ==> 0xFFFF
for(i=0; i
TempChar = *TextPtr;
index = ( CRCTemp ^ TempChar ) & 0x000F; // isolate low_order nibble
(who remeber this word?)
CRCTemp = (( CRCTemp>>4 ) & 0x0FFF) ^ crc_table[index];
TempChar >>= 4;
index = ( CRCTemp ^ TempChar ) & 0x000F;
CRCTemp = ( ( CRCTemp >> 4 ) & 0x0FFF ) ^ crc_table[index];
}
// return ~CRCTemp; // CRC-CCITT post conditioning - bit inversion
return CRCTemp;
}
#ifdef CRC_TEST
main(){
char test[10] = {91,28,36,44,50,67,0x7a,0x8e,93,0};
printf("%4x\n",crcCreate(10,test,0xffff));
}
#endif