aboutsummaryrefslogtreecommitdiff
path: root/bip39-standalone.html
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-11-30 18:55:12 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-11-30 18:55:12 +1100
commit94959756408aa60be4118ab1dceff4e71c6afdbf (patch)
tree8be863b99fd20341993d2afe0c70e16303157b06 /bip39-standalone.html
parentdedae1a9d604773143d13b496feeafd7b85084f4 (diff)
downloadBIP39-94959756408aa60be4118ab1dceff4e71c6afdbf.tar.gz
BIP39-94959756408aa60be4118ab1dceff4e71c6afdbf.tar.zst
BIP39-94959756408aa60be4118ab1dceff4e71c6afdbf.zip
bitsPerEvent correct for multiple decks of cards
Diffstat (limited to 'bip39-standalone.html')
-rw-r--r--bip39-standalone.html21
1 files changed, 14 insertions, 7 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html
index e433d31..4bad422 100644
--- a/bip39-standalone.html
+++ b/bip39-standalone.html
@@ -18324,9 +18324,13 @@ window.Entropy = new (function() {
18324 while (entropyBin.length < expectedBits) { 18324 while (entropyBin.length < expectedBits) {
18325 entropyBin = "0" + entropyBin; 18325 entropyBin = "0" + entropyBin;
18326 } 18326 }
18327 // Calculate the number of bits per event
18328 var bitsPerEvent = Math.log2(base.asInt);
18327 // Cards binary must be handled differently, since they're not replaced 18329 // Cards binary must be handled differently, since they're not replaced
18328 if (base.asInt == 52) { 18330 if (base.asInt == 52) {
18329 entropyBin = getCardBinary(base.parts); 18331 var cardEntropy = processCardEntropy(base.parts);
18332 entropyBin = cardEntropy.binaryStr;
18333 bitsPerEvent = cardEntropy.bitsPerEvent;
18330 } 18334 }
18331 // Supply a 'filtered' entropy string for display purposes 18335 // Supply a 'filtered' entropy string for display purposes
18332 var entropyClean = base.parts.join(""); 18336 var entropyClean = base.parts.join("");
@@ -18348,6 +18352,7 @@ window.Entropy = new (function() {
18348 binaryStr: entropyBin, 18352 binaryStr: entropyBin,
18349 cleanStr: entropyClean, 18353 cleanStr: entropyClean,
18350 cleanHtml: entropyHtml, 18354 cleanHtml: entropyHtml,
18355 bitsPerEvent: bitsPerEvent,
18351 base: base, 18356 base: base,
18352 } 18357 }
18353 return e; 18358 return e;
@@ -18440,7 +18445,7 @@ window.Entropy = new (function() {
18440 // total possible entropy is measured using n!, not base^n. 18445 // total possible entropy is measured using n!, not base^n.
18441 // eg the second last card can be only one of two, not one of fifty two 18446 // eg the second last card can be only one of two, not one of fifty two
18442 // so the added entropy for that card is only one bit at most 18447 // so the added entropy for that card is only one bit at most
18443 function getCardBinary(cards) { 18448 function processCardEntropy(cards) {
18444 // Track how many instances of each card have been used, and thus 18449 // Track how many instances of each card have been used, and thus
18445 // how many decks are in use. 18450 // how many decks are in use.
18446 var cardCounts = {}; 18451 var cardCounts = {};
@@ -18509,7 +18514,12 @@ window.Entropy = new (function() {
18509 } 18514 }
18510 // Truncate to the appropriate number of bits. 18515 // Truncate to the appropriate number of bits.
18511 entropyBin = entropyBin.substring(0, numberOfBits); 18516 entropyBin = entropyBin.substring(0, numberOfBits);
18512 return entropyBin; 18517 // Get the number of bits per event
18518 bitsPerEvent = maxBits / totalCards;
18519 return {
18520 binaryStr: entropyBin,
18521 bitsPerEvent: bitsPerEvent,
18522 }
18513 } 18523 }
18514 18524
18515 // Polyfill for Math.log2 18525 // Polyfill for Math.log2
@@ -19366,10 +19376,7 @@ window.Entropy = new (function() {
19366 } 19376 }
19367 var entropyTypeStr = getEntropyTypeStr(entropy); 19377 var entropyTypeStr = getEntropyTypeStr(entropy);
19368 var wordCount = Math.floor(numberOfBits / 32) * 3; 19378 var wordCount = Math.floor(numberOfBits / 32) * 3;
19369 var bitsPerEvent = Math.log2(entropy.base.asInt).toFixed(2); 19379 var bitsPerEvent = entropy.bitsPerEvent.toFixed(2);
19370 if (entropy.base.asInt == 52) {
19371 bitsPerEvent = (4.3381).toFixed(2); // log2(52! / 52)
19372 }
19373 DOM.entropyFiltered.html(entropy.cleanHtml); 19380 DOM.entropyFiltered.html(entropy.cleanHtml);
19374 DOM.entropyType.text(entropyTypeStr); 19381 DOM.entropyType.text(entropyTypeStr);
19375 DOM.entropyStrength.text(strength); 19382 DOM.entropyStrength.text(strength);