Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site amiga.amiga.UUCP Path: utzoo!linus!decvax!decwrl!pyramid!amiga!neil From: neil@amiga.UUCP (Neil Katin) Newsgroups: net.micro.amiga Subject: Dos hash function Message-ID: <987@amiga.amiga.UUCP> Date: Sat, 12-Apr-86 03:56:54 EST Article-I.D.: amiga.987 Posted: Sat Apr 12 03:56:54 1986 Date-Received: Mon, 14-Apr-86 00:43:47 EST Reply-To: neil@rocky.UUCP (Neil Katin) Organization: Commodore-Amiga Inc., 983 University Ave #D, Los Gatos CA 95030 Lines: 46 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 \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 ); }