diff options
-rw-r--r-- | src/js/entropy.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/js/entropy.js b/src/js/entropy.js index 5900346..f41cf80 100644 --- a/src/js/entropy.js +++ b/src/js/entropy.js | |||
@@ -7,6 +7,7 @@ | |||
7 | * dice 6 [1-6] | 7 | * dice 6 [1-6] |
8 | * decimal [0-9] | 8 | * decimal [0-9] |
9 | * hexadecimal [0-9A-F] | 9 | * hexadecimal [0-9A-F] |
10 | * card [A2-9TJQK][CDHS] | ||
10 | * | 11 | * |
11 | * Automatically uses lowest entropy to avoid issues such as interpretting 0101 | 12 | * Automatically uses lowest entropy to avoid issues such as interpretting 0101 |
12 | * as hexadecimal which would be 16 bits when really it's only 4 bits of binary | 13 | * as hexadecimal which would be 16 bits when really it's only 4 bits of binary |
@@ -119,11 +120,11 @@ window.Entropy = new (function() { | |||
119 | } | 120 | } |
120 | // Assume cards are NOT replaced. | 121 | // Assume cards are NOT replaced. |
121 | // Additional entropy decreases as more cards are used. This means | 122 | // Additional entropy decreases as more cards are used. This means |
122 | // entropy is measured using n!, not base^n. | 123 | // total possible entropy is measured using n!, not base^n. |
123 | // eg the second last card can be only one of two, not one of fifty two | 124 | // eg the second last card can be only one of two, not one of fifty two |
124 | // so the added entropy for that card is only one bit at most | 125 | // so the added entropy for that card is only one bit at most |
125 | if (base.asInt == 52) { | 126 | if (base.asInt == 52) { |
126 | // Get the maximum value without replacement | 127 | // Get the maximum value WITHOUT replacement |
127 | var totalDecks = Math.ceil(base.parts.length / 52); | 128 | var totalDecks = Math.ceil(base.parts.length / 52); |
128 | var totalCards = totalDecks * 52; | 129 | var totalCards = totalDecks * 52; |
129 | var totalCombos = factorial(52).pow(totalDecks); | 130 | var totalCombos = factorial(52).pow(totalDecks); |
@@ -140,7 +141,7 @@ window.Entropy = new (function() { | |||
140 | if (numberOfBits < 32) { | 141 | if (numberOfBits < 32) { |
141 | maxWithoutReplace = BigInteger(Math.round(Math.pow(2, numberOfBits))); | 142 | maxWithoutReplace = BigInteger(Math.round(Math.pow(2, numberOfBits))); |
142 | } | 143 | } |
143 | // Get the maximum value with replacement | 144 | // Get the maximum value WITH replacement |
144 | var maxWithReplace = BigInteger.pow(52, base.parts.length); | 145 | var maxWithReplace = BigInteger.pow(52, base.parts.length); |
145 | // Calculate the new value by scaling the original value down | 146 | // Calculate the new value by scaling the original value down |
146 | var withoutReplace = entropyInt.multiply(maxWithoutReplace).divide(maxWithReplace); | 147 | var withoutReplace = entropyInt.multiply(maxWithoutReplace).divide(maxWithReplace); |
@@ -166,6 +167,7 @@ window.Entropy = new (function() { | |||
166 | entropyHtml = entropyHtml.replace(/H/g, "<span class='card-suit heart'>\u2665</span>"); | 167 | entropyHtml = entropyHtml.replace(/H/g, "<span class='card-suit heart'>\u2665</span>"); |
167 | entropyHtml = entropyHtml.replace(/S/g, "<span class='card-suit spade'>\u2660</span>"); | 168 | entropyHtml = entropyHtml.replace(/S/g, "<span class='card-suit spade'>\u2660</span>"); |
168 | } | 169 | } |
170 | // Return the result | ||
169 | var e = { | 171 | var e = { |
170 | binaryStr: entropyBin, | 172 | binaryStr: entropyBin, |
171 | cleanStr: entropyClean, | 173 | cleanStr: entropyClean, |