Created
January 30, 2017 04:26
-
-
Save VictorTaelin/b7328d5184d19b1ad73c02c4fa205db1 to your computer and use it in GitHub Desktop.
hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hash(bits, len){ | |
var tt = [1,2,0,0,0,1,1,2,2]; | |
var st = []; | |
for (var i=0; i<128; ++i) | |
st.push(i%3); | |
var os = []; | |
for (var k=0, l=st.length, il=bits.length; k<il+len; ++k){ | |
for (var j=0; j<32; ++j){ | |
if (k < il) | |
st[0] = bits[k]; | |
for (var i=j%2; i<l; i+=2){ | |
var x = i%l; | |
var y = (i+1)%l; | |
var a = st[x]; | |
var b = st[y]; | |
st[x] = tt[a*3+b]; | |
st[y] = tt[b*3+a]; | |
}; | |
}; | |
if (k >= il) | |
os.push((st[0] + st[1]*3 + st[2]*9 + st[3]*27) % 2); | |
}; | |
return os; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment