]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - src/js/entropy.js
Entropy with more than 4 decks can be calculated
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / entropy.js
index b7274bbea7ccb5781aa084b45d0219d5e99e4e0e..24fc21a47b4da47565bfde3621fd8ba6285351f2 100644 (file)
@@ -263,7 +263,12 @@ window.Entropy = new (function() {
         }
         // Work out the total number of bits for this many decks
         // See http://crypto.stackexchange.com/q/41886
-        var gainedBits = Math.log2(factorial(52 * numberOfDecks));
+        var gainedBits = 0;
+        // Equivalent of Math.log2(factorial(52*numberOfDecks))
+        // which becomes infinity for numberOfDecks > 4
+        for (var i=1; i<=52*numberOfDecks; i++) {
+            gainedBits = gainedBits + Math.log2(i);
+        }
         var lostBits = 52 * Math.log2(factorial(numberOfDecks));
         var maxBits = gainedBits - lostBits;
         // Convert the drawn cards to a binary representation.