Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 10 additions & 17 deletions hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 3 additions & 2 deletions hash/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions hash/test_program.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}