1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _CCIT_POLYNOME 0x04c11db7
#define _CCIT_INIT_VALUE 0x00000000
/**************************************************/
/*Types definition*/
typedef unsigned long long int uint_64; /*unsigned 64bits*/
typedef unsigned int uint_32; /*unsigned 32bits*/
typedef unsigned short uint_16; /*unsigned 16bits*/
typedef unsigned char uint_8; /*unsigned 8bits*/
typedef union{
uint_64 value;
struct{
uint_8 tail;
uint_32 remainder;
uint_8 head;
}part;
}CRC32_PART;
/**************************************************/
/**************************************************/
/*Global declarations*/
static CRC32_PART ccit_reg;
/**************************************************/
/**************************************************/
/*functions*/
void OneBytesCrc32 (uint_8 byte){
int bitscounter = 8;
ccit_reg.part.tail = byte;
do{
ccit_reg.value <<= 1;
if (ccit_reg.part.head & 0x01)
ccit_reg.part.remainder ^= _CCIT_POLYNOME;
}while (--bitscounter);
}
uint_32 StringtoCCIT32 (char* str, unsigned len){
int i;
ccit_reg.part.remainder = _CCIT_INIT_VALUE;
for (i=0; i<len; i++)
OneBytesCrc32 (str[i]);
OneBytesCrc32 (0x00);
OneBytesCrc32 (0x00);
//OneBytesCrc32 (0x00);
//OneBytesCrc32 (0x00);
return ccit_reg.part.remainder;
}
/**************************************************/
int main (int argc, char* argv[]){
char *p = "Developpez";
uint_32 crc;
crc = StringtoCCIT32 (p, strlen (p));
printf ("0x%x\n", crc);
return 0;
} |
Partager