From 960f3c4f36ab20c29d7575fbd5f51615ec1a2b05 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Wed, 18 Jan 2017 08:46:45 +0100 Subject: [PATCH] Only alter last bit also in non persistent rng mode. Fixes #99. --- lib/modifiedAPI.js | 2 +- lib/randomSupplies.js | 25 +++---------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/lib/modifiedAPI.js b/lib/modifiedAPI.js index 3f74878..530a8d8 100644 --- a/lib/modifiedAPI.js +++ b/lib/modifiedAPI.js @@ -46,7 +46,7 @@ var l = desc.length; var rng = randomSupply.getRng(l, window); - for (var i = 0; i < l; i += 10){ + for (var i = 0; i < l; i += 1){ desc[i] = rng(source[i], i); } var canvas = original.cloneNode(true); diff --git a/lib/randomSupplies.js b/lib/randomSupplies.js index 83552b4..0058885 100644 --- a/lib/randomSupplies.js +++ b/lib/randomSupplies.js @@ -28,7 +28,7 @@ // extract the bit var bit = (bitSet[index] >>> bitIndex) & 0x01; - // XOR the bit the the value to alter the last bit of it... or not + // XOR the bit and the value to alter the last bit of it... or not return value ^ bit; }; } @@ -52,27 +52,8 @@ var rnd = randomNumbers[randomI]; randomI += 1; - // do not alter the most significant bit that is set and - // the bit after it, to not disturb the image too much. - if (value >= 0x80){ - value = value ^ (rnd & 0x1F); - } - else if (value >= 0x40){ - value = value ^ (rnd & 0x0F); - } - else if (value >= 0x20){ - value = value ^ (rnd & 0x07); - } - else if (value >= 0x10){ - value = value ^ (rnd & 0x03); - } - else if (value >= 0x08){ - value = value ^ (rnd & 0x01); - } - // else if (value >= 0x04){ - // value = value ^ (rnd * 0x00); - // } - return value; + // XOR the last bit to alter it... or not + return value ^ (rnd & 0x01); }; } };