From f8ca25c3381d5071426497eb3bf34ff5cdf094ee Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Mon, 12 Mar 2018 10:33:07 +1100 Subject: [PATCH] Add spacing every 11 bits to the checksum --- src/js/index.js | 11 ++++++++++- tests/spec/tests.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/js/index.js b/src/js/index.js index 0d573ba..b8a76a9 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1228,7 +1228,7 @@ var entropyTypeStr = getEntropyTypeStr(entropy); var wordCount = Math.floor(numberOfBits / 32) * 3; var bitsPerEvent = entropy.bitsPerEvent.toFixed(2); - var spacedBinaryStr = entropy.binaryStr.match(/.{1,11}/g).join(" " ); + var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr); DOM.entropyFiltered.html(entropy.cleanHtml); DOM.entropyType.text(entropyTypeStr); DOM.entropyCrackTime.text(timeToCrack); @@ -1479,6 +1479,11 @@ var start = binaryStr.length - checksumBitlength; var end = binaryStr.length; checksum = binaryStr.substring(start, end); + // add spaces so the last group is 11 bits, not the first + checksum = checksum.split("").reverse().join("") + checksum = addSpacesEveryElevenBits(checksum); + checksum = checksum.split("").reverse().join("") + break; } } DOM.entropyChecksum.text(checksum); @@ -1504,6 +1509,10 @@ DOM.csv.val(tableCsv); } + function addSpacesEveryElevenBits(binaryStr) { + return binaryStr.match(/.{1,11}/g).join(" "); + } + var networks = [ { name: "AXE - Axe", diff --git a/tests/spec/tests.js b/tests/spec/tests.js index f56b18d..c7a9889 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -2937,4 +2937,21 @@ it('Shows the checksum for the entropy', function(done) { }); }); +it('Shows the checksum for the entropy with the correct groupings', function(done) { + driver.findElement(By.css('.use-entropy')) + .click(); + // create a checksum of 20 bits, which spans multiple words + driver.findElement(By.css('.entropy')) + .sendKeys("F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"); + driver.sleep(generateDelay).then(function() { + driver.findElement(By.css('.checksum')) + .getText() + .then(function(text) { + // first group is 9 bits, second group is 11 + expect(text).toBe("011010111 01110000110"); + done(); + }); + }); +}); + }); -- 2.41.0