CRC32加密函数

typedef unsigned int uint;
uint POLYNOMIAL = 0xEDB88320;
int have_table = 0;
uint table[256];

void make_table()
{
    int i, j, crc;
    have_table = 1;
    for (i = 0; i < 256; i++)
        for (j = 0, table[i] = i; j < 8; j++)
            table[i] = (table[i] >> 1) ^ ((table[i] & 1) ? POLYNOMIAL : 0);
}

uint crc32(uint crc,char *buff, int len)
{
    if (!have_table) make_table();
    crc = crc ^ ~0U;
    for (int i = 0; i < len; i++)
        crc = (crc >> 8) ^ table[(crc ^ buff[i]) & 0xFF];
    return ~crc;
}
    //CRC32加密
    uint encoded_crc32 = crc32(0, encoded_md5, 16);
    printf("crc32 : %08X",encoded_crc32 );

 

上一篇:币安链BSC插件钱包指南


下一篇:基于Java的32位CRC校验分享