#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define NUM			123
#define HASH_MULTIPLIER		33
//#define P	0x01000193U

static unsigned int djb2_hash(const void *input, const unsigned int size)
{
	const unsigned char *data = input;
	unsigned int i, hash;

	hash = 0;
	for (i=0; i<size; ++i) {
		hash *= HASH_MULTIPLIER;
		hash += data[i];
	}

	return hash;
}

int main()
{
	unsigned char a[NUM];
	unsigned int h, hash;
	int i;

	srand(time(NULL));

	for (i=0; i<NUM; ++i) {
		a[i] = 1 + (int) (255.0 * (rand() / (RAND_MAX + 1.0)));
	}

	hash = djb2_hash(a, NUM);

	h = 0;
	for (i=0; i<NUM; ++i) {
		int j;
		unsigned int t;

		t = 1;
		for (j=0; j<i; ++j)
			t *= HASH_MULTIPLIER;
		h += t * a[NUM-i-1];
	}

	printf("hash: %08x, H: %08x.\n", hash, h);
	return 0;
}

