diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2016-11-16 12:21:17 +1100 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2016-11-16 12:43:08 +1100 |
commit | fc8c40413313d83c3bce334fbab2fa866751713e (patch) | |
tree | 03e1910efcbabebfb31fb83a6451220cc507ae42 /src/js | |
parent | 9bc39377aa0317ffbfed3b6e29814bb26681cfd5 (diff) | |
download | BIP39-fc8c40413313d83c3bce334fbab2fa866751713e.tar.gz BIP39-fc8c40413313d83c3bce334fbab2fa866751713e.tar.zst BIP39-fc8c40413313d83c3bce334fbab2fa866751713e.zip |
Multiple decks of cards are possible
but also a needless oversupply of entropy
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/index.js | 10 |
1 files changed, 7 insertions, 3 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 | } |