From 391c7f267f6be3356d0bffa74e2726245b5f45b2 Mon Sep 17 00:00:00 2001 From: Ian Coleman Date: Wed, 16 Nov 2016 11:46:25 +1100 Subject: Card duplicates and use of full deck is detected --- src/js/index.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/js/index.js b/src/js/index.js index 89f8d0d..e064185 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -820,8 +820,9 @@ } var bitsStr = getNumberOfEntropyBits(entropy); var wordCount = Math.floor(entropy.binaryStr.length / 32) * 3; + var entropyTypeStr = getEntropyTypeStr(entropy); DOM.entropyFiltered.html(entropy.cleanHtml); - DOM.entropyType.text(entropy.base.str); + DOM.entropyType.text(entropyTypeStr); DOM.entropyStrength.text(strength); DOM.entropyEventCount.text(entropy.base.ints.length); DOM.entropyBits.text(bitsStr); @@ -847,6 +848,48 @@ return bitsStr } + function getEntropyTypeStr(entropy) { + var typeStr = entropy.base.str; + // Add some detail if these are cards + if (entropy.base.asInt == 52) { + var cardDetail = []; // array of message strings + // Detect duplicates + var dupes = []; + var dupeTracker = {}; + for (var i=0; i 0) { + var dupeWord = "duplicates"; + if (dupes.length == 1) { + dupeWord = "duplicate"; + } + var msg = dupes.length + " " + dupeWord + ": " + dupes.slice(0,3).join(" "); + if (dupes.length > 3) { + msg += "..."; + } + cardDetail.push(msg); + } + // Detect full deck + var uniqueCards = []; + for (var uniqueCard in dupeTracker) { + uniqueCards.push(uniqueCard); + } + if (uniqueCards.length == 52) { + cardDetail.unshift("full deck"); + } + // Add card details to typeStr + if (cardDetail.length > 0) { + typeStr += " (" + cardDetail.join(", ") + ")"; + } + } + return typeStr; + } + // Depends on BigInteger function factorial(n) { if (n == 0) { -- cgit v1.2.3