Fixed CRC-32 Error

This commit is contained in:
ChatN0ir 2019-10-14 17:49:03 +02:00
parent 71738b36a9
commit ca18351173
3 changed files with 14 additions and 19 deletions

View File

@ -63,25 +63,18 @@ int adler_32(char s[])
}
/* crc32 Hash-Algorithm*/
#include <inttypes.h>
int crc32(char string[])
{
uint32_t crc32(char* data){
int i = 0;
unsigned int cur_crc, masking;
cur_crc = 0xFFFFFFFF;
while(string[i] != '\0')
{
unsigned int byte = string[i];
cur_crc = cur_crc ^ byte;
uint32_t crc = 0xffffffff;
while(data[i] != '\0'){
uint8_t byte = data[i];
crc = crc ^ byte;
for(int j = 8; j > 0; --j)
{
masking = -(cur_crc & 1);
cur_crc = (cur_crc >> 1) ^ (0xEDB88320 & masking);
}
crc = (crc >> 1) ^ (0xEDB88320 & ( -(crc & 1)));
i++;
}
return -cur_crc;
}
return crc ^ 0xffffffff;
}

View File

@ -41,10 +41,11 @@ char xor8(char[]);
int adler_32(char[]);
/*
crc32: implements the crc-32 hash-algorithm
returns the checksum byte for the passed byte
crc32: implements the crc-32 checksum-algorithm
returns the crc-32 checksum
*/
int crc32(char[]);
#endif

View File

@ -16,6 +16,7 @@ int main(void)
printf("xor8: %s --> %i\n", s, xor8(s)); /* 8 bit */
printf("adler_32: %s --> %i\n", s, adler_32(s)); /* 32 bit */
printf("crc32: %s --> %i\n", s, crc32(s));
return 0;
}