This is the source code for the GenerateMasterCode() function. Could anyone possibly help me in converting this to PHP? I would be so extremely grateful.
int slow_crc32(int sum, char *p, int len)
{
while (len--)
{
int i;
char byte = *p++;
for (i = 0; i < 8; ++i)
{
int osum = sum;
sum <<= 1;
if (byte & 0x80)
sum |= 1 ;
if (osum & 0x80000000)
sum ^= POLY;
byte <<= 1;
}
}
return sum;
}
void WordToHex(char *p,unsigned int c)
{
unsigned int b = c;
unsigned int mask=0xF0000000;
char i,shift=28;
for(i=0;i<8;i++){
c = b & mask;
c = c >> shift;
if(c>9)
c += 0x37;
else
c += 0x30;
*p++=c;
mask >>= 4;
//mask = mask >> 4;
shift -= 4;
}
}
int __stdcall GenerateMasterCode(char *message, char *imei, char *code)
{
volatile int crc = var1 ^ var2;
char buf[4]={0,0,0,0};
if(strlen(message)==0){
return -1;
}
if(strlen(imei)==0){
return -1;
}
if(strlen(message)>127){
return -1;
}
if(strlen(imei)>127){
return -1;
}
crc=slow_crc32(crc, imei, strlen(imei));
crc=slow_crc32(crc, buf, 4);
crc=slow_crc32(crc, message, strlen(message));
crc=slow_crc32(crc, buf, 4);
WordToHex(code,crc);
*(code+8)=0;
return 0;
}