Reputation: 1
I received the following piece of source code which generates a proprietary CRC value of an input string. Can you pls help to identify the language and suggest in which tool/environment can I compile and make it work. Thanks
WORD CalcCRC(BYTE *pstr, WORD len)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
WORD crc;
WORD i;
crc = 0; // initialise CRC
for (i = 0; i<len; i++) // calculate CRC for every single byte
{
CRCBYT(*pstr, &crc);
pstr++;
}
return crc;
}
void CRCBYT(unsigned char byt, WORD *pcrc)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
int i;
WORD fl1;
for (i = 0; i<8; i++)
{
fl1 = ((*pcrc) & 0x8000); //MSB = 1?
(*pcrc) <<= 1; //CRC shift left
if (byt & 0x80) //MSB = 1?
(*pcrc)++; //Byte shift left
byt <<= 1;
if (fl1) //if fl1 XOR of CRC
(*pcrc) ^= 0x1021;
}
}
Upvotes: 0
Views: 48
Reputation: 37122
It comes from Windows, but if you take out the AFX_MANAGE_STATE
lines (which don't appear to be needed) it should compile in any C or C++ compiler.
You may need to add the following typedefs if you're not compiling for Windows:
typedef unsigned short WORD;
typedef unsigned char BYTE;
Upvotes: 4