Jump to content

Help!! C++ code to PHP


gabstore

Recommended Posts

Hi. i m a newbie .

can anyone help me to convert the c++ source below in to php ? PLs........

=========================================================

#pragma once

 

#define CRC32 CCrc::Crc

 

#define POLYNOMIAL 0x04C11XXXX

 

class CCrc

{

public:

 

CCrc() { }

~CCrc();

 

static DWORD CrcTable[256];

static VOID  InitCrcTable();

static DWORD Crc(LPCTSTR pData);

private:

 

static BOOL m_bInitCrc;

 

};

==========================================================

 

&

 

==========================================================

#include "stdafx.h"

#include "crc.h"

 

 

DWORD CCrc::CrcTable[256];

BOOL  CCrc::m_bInitCrc = FALSE;

 

//-----------------------------------------------------------------------------

// generate the table of CRC remainders for all possible bytes

//-----------------------------------------------------------------------------

VOID CCrc::InitCrcTable()

{

static bool bInited = false;

 

if (bInited)

return;

 

register int i, j;

register unsigned long crc_accum;

for ( i = 0;  i < 256;  i++ )

{

crc_accum = ( (unsigned long) i << 24 );

for ( j = 0;  j < 8;  j++ )

{

if( crc_accum & 0x80000000L )

crc_accum = ( crc_accum << 1 ) ^ POLYNOMIAL;

else

crc_accum = ( crc_accum << 1 );

}

CrcTable = crc_accum;

}

 

bInited = true;

}

 

 

 

 

//-----------------------------------------------------------------------------

// calculate 32 crc

//-----------------------------------------------------------------------------

DWORD CCrc::Crc(LPCTSTR lpData)

{

if( FALSE == m_bInitCrc )

{

InitCrcTable();

m_bInitCrc = TRUE;

}

unsigned int result;

 

 

const unsigned char *data = (const unsigned char *)lpData;

if( data[0] == 0 ) return 0;

 

result  = *data++ << 24;

if( *data )

{

result |= *data++ << 16;

if( *data )

{

result |= *data++ << 8;

if( *data ) result |= *data++;

}

}

result = ~ result;

 

while( *data )

{

result = (result << 8 | *data) ^ CrcTable[result >> 24];

data++;

}

 

return ~result;

}

==========================================================

Link to comment
https://forums.phpfreaks.com/topic/69147-help-c-code-to-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.