Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Rate My Awesome Cryptographic Hash Algorithm

Name: Anonymous 2014-05-25 20:36


unsigned long hash(unsigned char *str)
{
unsigned int hash = 0;
int c;

while (c = *str++)
{
hash += c;
}

return hash;
}


Spent hours designing it. It is safer than md5!

Name: Anonymous 2014-05-28 0:49

>>1
You invoke undefined behaviour, when str points one beyond the 0 char. Consider:

foo = malloc(1);
if(foo) {
*foo = 0;
hash(foo); // bam trap representation, UB invoked inside hash()
free(foo);
}


If you were a C masta you'd also know of the subtlety that this isn't UB when you use hash() with arrays. You're allowed to point one past the last element of an array.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List