File:  [gforth] / gforth / xhash.fs
Revision 1.1: download - view: text, annotated - select for diffs
Thu May 22 19:38:30 2008 UTC (9 years, 5 months ago) by pazsan
Branches: MAIN
CVS tags: v0-7-0, HEAD
Added xorshift rng+hash

\ a more secure hash using xorshift RNG

Variable seed
cell 4 = [IF]
: xorshift ( n -- n' )
    dup 1 lshift xor
    dup 3 rshift xor
    dup 10 lshift xor ;
[THEN]
cell 8 = [IF]
: xorshift ( n -- n' )
    dup 11 lshift xor
    dup 23 rshift xor
    dup 56 lshift xor ;
[THEN]
: rnd  seed @ xorshift dup seed ! ;

: xhash ( addr u -- hash )
    0 -rot bounds ?DO
	I c@ xor xorshift
    LOOP ;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>