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

    1: \ a more secure hash using xorshift RNG
    2: 
    3: Variable seed
    4: cell 4 = [IF]
    5: : xorshift ( n -- n' )
    6:     dup 1 lshift xor
    7:     dup 3 rshift xor
    8:     dup 10 lshift xor ;
    9: [THEN]
   10: cell 8 = [IF]
   11: : xorshift ( n -- n' )
   12:     dup 11 lshift xor
   13:     dup 23 rshift xor
   14:     dup 56 lshift xor ;
   15: [THEN]
   16: : rnd  seed @ xorshift dup seed ! ;
   17: 
   18: : xhash ( addr u -- hash )
   19:     0 -rot bounds ?DO
   20: 	I c@ xor xorshift
   21:     LOOP ;

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