[gforth] / gforth / xhash.fs  

gforth: gforth/xhash.fs

File: [gforth] / gforth / xhash.fs (download)
Revision: 1.1, Thu May 22 19:38:30 2008 UTC (4 years, 11 months ago) by pazsan
Branch: 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 ;

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help