djb2 algorithm for C
#include <stdio.h>
unsigned long djb2_hash(const char *str) {
unsigned long hash = 5381;
int c;
while ((c = *str++)) {
hash = ((hash << 5) + hash) + c; / hash 33 + c */
}
return hash;
}
int main() {
const char *input_str = "Hello, djb2!";
unsigned long hash_value = djb2_hash(input_str);
printf("Hash value for \"%s\": %lu\n", input_str, hash_value);
return 0;
}