]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Multiple decks of cards are possible
authorIan Coleman <coleman.ian@gmail.com>
Wed, 16 Nov 2016 01:21:17 +0000 (12:21 +1100)
committerIan Coleman <coleman.ian@gmail.com>
Wed, 16 Nov 2016 01:43:08 +0000 (12:43 +1100)
but also a needless oversupply of entropy

src/js/index.js
tests.js

index dbbd382e406de4ca6e999e3ad62d880e335e8089..f354399cc2d09130601cc1d1136fd07297cf99ae 100644 (file)
         // eg the second last card can be only one of two, not one of fifty two
         // so the added entropy for that card is only one bit at most
         if (entropy.base.asInt == 52) {
-            var totalCombos = factorial(52);
-            var remainingCards = 52 - entropy.base.parts.length;
-            var remainingCombos = factorial(remainingCards);
+            var totalDecks = Math.ceil(entropy.base.parts.length / 52);
+            var totalCards = totalDecks * 52;
+            var totalCombos = factorial(52).pow(totalDecks);
+            var totalRemainingCards = totalCards - entropy.base.parts.length;
+            var remainingDecks = Math.floor(totalRemainingCards / 52);
+            var remainingCards = totalRemainingCards % 52;
+            var remainingCombos = factorial(52).pow(remainingDecks) * factorial(remainingCards);
             var currentCombos = totalCombos.divide(remainingCombos);
             bitsStr = currentCombos.toString(2).length.toString();
         }
index 1b1d44577a91b01e8addb301c54b707c594610c8..189f1eaf1c9783c272b9a075f972ad13fbfb52d0 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -2644,7 +2644,7 @@ page.open(url, function(status) {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
             type: "card (full deck, 1 duplicate: 3d)",
             events: 53,
-            bits: 226,
+            bits: 232,
             words: 27,
             strength: "extremely strong",
         },
@@ -2652,7 +2652,7 @@ page.open(url, function(status) {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
             type: "card (2 duplicates: 3d 4d)",
             events: 53,
-            bits: 226,
+            bits: 232,
             words: 27,
             strength: "extremely strong",
         },
@@ -2660,7 +2660,7 @@ page.open(url, function(status) {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
             type: "card (4 duplicates: 3d 4d 5d...)",
             events: 53,
-            bits: 226,
+            bits: 243,
             words: 27,
             strength: "extremely strong",
         },
@@ -2669,7 +2669,7 @@ page.open(url, function(status) {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
             type: "card (full deck, 52 duplicates: ac 2c 3c...)",
             events: 104,
-            bits: 226,
+            bits: 452,
             words: 54,
             strength: "extremely strong",
         },