⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc.cpp

📁 Diamond加密算法 vc++源程序
💻 CPP
字号:
/* crc.cpp -- contains table based CCITT 32 bit CRC function.
   This file is in the Public Domain.
*/

#define CRC_MASK           0xFFFFFFFFL
#define CRC32_POLYNOMIAL   0xEDB88320L

#include "def.h"
#include "crc.h"

unsigned long  *Ccitt32Table = (unsigned long *)NULL;

/****************************************************************************/

/*
 * This routine simply builds the coefficient table used to calculate
 * 32 bit CRC values throughout this program.  The 256 long word table
 * has to be set up once when the program starts.  Alternatively, the
 * values could be hard coded in, which would offer a miniscule improvement
 * in overall performance of the program.
 */

int CALLTYPE BuildCRCTable(void)
    {
    int i;
    int j;
    unsigned long value;

    if (Ccitt32Table)
        return 0;
    Ccitt32Table = new unsigned long int[256];
    if (Ccitt32Table == NULL)
        {
        return 1;
        }
    for ( i = 0; i <= 255 ; i++ )
        {
        value = i;
        for ( j = 8 ; j > 0; j-- )
            {
            if ( value & 1 )
                value = ( value >> 1 ) ^ CRC32_POLYNOMIAL;
            else
                value >>= 1;
            }
        Ccitt32Table[ i ] = value;
        }
    return 0;
    }


void CALLTYPE crc32done(void)
    {
    if (Ccitt32Table)
        {
        delete Ccitt32Table;
        Ccitt32Table = (unsigned long*)NULL;
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -