neil@amiga.UUCP (Neil Katin) (04/12/86)
Recently several people have asked for the dos directory hash function. Here is a small program that computes it. The hash value is the longword offset into the directory block, NOT into the hash table (I just love that BCPL...). Anyway, hope it helps. Neil Katin Commodore-Amiga Inc. pyramid!amiga!neil ---- cut here -------------------- main( argc, argv ) int argc; char **argv; { if( argc != 2 ) { printf( "Usage: %s <name>\n", argv[0] ); exit( 1 ); } printf( "hash is %ld\n", (hash( argv[1] ) % 72) + 6 ); } hash( s ) unsigned char *s; { int i; int res; unsigned char *sp; unsigned c; res = strlen( s ); for( i = 1, sp = s; *sp; i++, sp++ ) { c = *sp; if( c >= 'a' && c <= 'z' ) { c = c - 'a' + 'A'; } res = ((res * 13 + c ) & 0x7ff); } return( res ); }