aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-11-16 12:21:17 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-11-16 12:43:08 +1100
commitfc8c40413313d83c3bce334fbab2fa866751713e (patch)
tree03e1910efcbabebfb31fb83a6451220cc507ae42
parent9bc39377aa0317ffbfed3b6e29814bb26681cfd5 (diff)
downloadBIP39-fc8c40413313d83c3bce334fbab2fa866751713e.tar.gz
BIP39-fc8c40413313d83c3bce334fbab2fa866751713e.tar.zst
BIP39-fc8c40413313d83c3bce334fbab2fa866751713e.zip
Multiple decks of cards are possible
but also a needless oversupply of entropy
-rw-r--r--src/js/index.js10
-rw-r--r--tests.js8
2 files changed, 11 insertions, 7 deletions
diff --git a/src/js/index.js b/src/js/index.js
index dbbd382..f354399 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -846,9 +846,13 @@
846 // eg the second last card can be only one of two, not one of fifty two 846 // eg the second last card can be only one of two, not one of fifty two
847 // so the added entropy for that card is only one bit at most 847 // so the added entropy for that card is only one bit at most
848 if (entropy.base.asInt == 52) { 848 if (entropy.base.asInt == 52) {
849 var totalCombos = factorial(52); 849 var totalDecks = Math.ceil(entropy.base.parts.length / 52);
850 var remainingCards = 52 - entropy.base.parts.length; 850 var totalCards = totalDecks * 52;
851 var remainingCombos = factorial(remainingCards); 851 var totalCombos = factorial(52).pow(totalDecks);
852 var totalRemainingCards = totalCards - entropy.base.parts.length;
853 var remainingDecks = Math.floor(totalRemainingCards / 52);
854 var remainingCards = totalRemainingCards % 52;
855 var remainingCombos = factorial(52).pow(remainingDecks) * factorial(remainingCards);
852 var currentCombos = totalCombos.divide(remainingCombos); 856 var currentCombos = totalCombos.divide(remainingCombos);
853 bitsStr = currentCombos.toString(2).length.toString(); 857 bitsStr = currentCombos.toString(2).length.toString();
854 } 858 }
diff --git a/tests.js b/tests.js
index 1b1d445..189f1ea 100644
--- a/tests.js
+++ b/tests.js
@@ -2644,7 +2644,7 @@ page.open(url, function(status) {
2644 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d", 2644 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
2645 type: "card (full deck, 1 duplicate: 3d)", 2645 type: "card (full deck, 1 duplicate: 3d)",
2646 events: 53, 2646 events: 53,
2647 bits: 226, 2647 bits: 232,
2648 words: 27, 2648 words: 27,
2649 strength: "extremely strong", 2649 strength: "extremely strong",
2650 }, 2650 },
@@ -2652,7 +2652,7 @@ page.open(url, function(status) {
2652 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d", 2652 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
2653 type: "card (2 duplicates: 3d 4d)", 2653 type: "card (2 duplicates: 3d 4d)",
2654 events: 53, 2654 events: 53,
2655 bits: 226, 2655 bits: 232,
2656 words: 27, 2656 words: 27,
2657 strength: "extremely strong", 2657 strength: "extremely strong",
2658 }, 2658 },
@@ -2660,7 +2660,7 @@ page.open(url, function(status) {
2660 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d", 2660 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
2661 type: "card (4 duplicates: 3d 4d 5d...)", 2661 type: "card (4 duplicates: 3d 4d 5d...)",
2662 events: 53, 2662 events: 53,
2663 bits: 226, 2663 bits: 243,
2664 words: 27, 2664 words: 27,
2665 strength: "extremely strong", 2665 strength: "extremely strong",
2666 }, 2666 },
@@ -2669,7 +2669,7 @@ page.open(url, function(status) {
2669 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", 2669 entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
2670 type: "card (full deck, 52 duplicates: ac 2c 3c...)", 2670 type: "card (full deck, 52 duplicates: ac 2c 3c...)",
2671 events: 104, 2671 events: 104,
2672 bits: 226, 2672 bits: 452,
2673 words: 54, 2673 words: 54,
2674 strength: "extremely strong", 2674 strength: "extremely strong",
2675 }, 2675 },