function Foo(x, y)
{
const Zi = new Uint32Array(4);
const Vi = new Uint32Array(y);
for (let i = 0; i < 128; i++) {
const xi = (x[i >> 5] & (1 << (31 - (i % 32)))) !== 0;
if (xi) {
Zi[0] ^= Vi[0];
Zi[1] ^= Vi[1];
Zi[2] ^= Vi[2];
Zi[3] ^= Vi[3];
}
const lsbValue = Vi[3] & 1;
Vi[3] = (Vi[3] >>> 1) | ((Vi[2] & 1) << 31);
Vi[2] = (Vi[2] >>> 1) | ((Vi[1] & 1) << 31);
Vi[1] = (Vi[1] >>> 1) | ((Vi[0] & 1) << 31);
Vi[0] = Vi[0] >>> 1;
if (lsbValue) {
Vi[0] ^= 0xe1000000;
}
}
return Zi;
}
function Bar(x, y) {
const Zi = new Uint32Array(4);
const Vi = new Uint32Array(y);
for (let i = 0; i < 128; i++) {
const xi = (x[i >> 5] & (1 << (31 - (i % 32)))) !== 0;
if (xi) {
Zi[0] ^= Vi[0];
Zi[1] ^= Vi[1];
Zi[2] ^= Vi[2];
Zi[3] ^= Vi[3];
}
let lsbValue = !!(Vi[3] & 1 ) ;
Vi[3] = (Vi[3] >>> 1) | ((Vi[2] & 1) << 31);
Vi[2] = (Vi[2] >>> 1) | ((Vi[1] & 1) << 31);
Vi[1] = (Vi[1] >>> 1) | ((Vi[0] & 1) << 31);
Vi[0] = Vi[0] >>> 1;
if (lsbValue) {
Vi[0] ^= 0xe1000000;
}
}
return Zi;
}
function testGalois(fn) {
const x = new Uint32Array([2425393296, 2425393296, 2425393296, 2425393296]);
const y = new Uint32Array([3692772234, 3144594163, 3014792419, 2386452453]);
const expected = [2793996538, 14267392, 3369100906, 2506634262];
for (let i = 0; i < 100; i++) {
const result = Array.from(fn(x, y));
if (JSON.stringify(result) != JSON.stringify(expected)) {
console.error('Failed on iteration', i, 'expected', expected, 'result', result)
return;
}
}
console.log('Pass!');
}
console.log('Testing Foo')
testGalois(Foo);
console.log('Testing Bar')
testGalois(Bar);
To embed this project on your website, copy the following code and paste it into your website's HTML: