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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.