gabstore Posted September 13, 2007 Share Posted September 13, 2007 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; } ========================================================== Quote Link to comment Share on other sites More sharing options...
btherl Posted September 13, 2007 Share Posted September 13, 2007 Does this help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.