aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-11-16 11:19:49 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-11-16 11:19:49 +1100
commit02f05d3e467ba8ccf3fca2811eda847fc71e511f (patch)
tree08bbfd6cd083d8b957e86fc36207460fbc69b720 /src
parentb6dbc2a1aea8eeab2d41a4d44f9d7522ecc59a50 (diff)
downloadBIP39-02f05d3e467ba8ccf3fca2811eda847fc71e511f.tar.gz
BIP39-02f05d3e467ba8ccf3fca2811eda847fc71e511f.tar.zst
BIP39-02f05d3e467ba8ccf3fca2811eda847fc71e511f.zip
Entropy strength for cards assumes no replacement
Diffstat (limited to 'src')
-rw-r--r--src/js/index.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/js/index.js b/src/js/index.js
index b03f2c8..89f8d0d 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -818,7 +818,7 @@
818 strength = strength + " - " + z.feedback.warning; 818 strength = strength + " - " + z.feedback.warning;
819 }; 819 };
820 } 820 }
821 var bitsStr = entropy.binaryStr.length; 821 var bitsStr = getNumberOfEntropyBits(entropy);
822 var wordCount = Math.floor(entropy.binaryStr.length / 32) * 3; 822 var wordCount = Math.floor(entropy.binaryStr.length / 32) * 3;
823 DOM.entropyFiltered.html(entropy.cleanHtml); 823 DOM.entropyFiltered.html(entropy.cleanHtml);
824 DOM.entropyType.text(entropy.base.str); 824 DOM.entropyType.text(entropy.base.str);
@@ -830,6 +830,35 @@
830 DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2)); 830 DOM.entropyBitsPerEvent.text(Math.log2(entropy.base.asInt).toFixed(2));
831 } 831 }
832 832
833 function getNumberOfEntropyBits(entropy) {
834 var bitsStr = entropy.binaryStr.length.toString();
835 // If using cards, assume they are not reused, thus additional entropy
836 // decreases as more cards are used. This means entropy is measured
837 // using n!, not base^n.
838 // eg the second last card can be only one of two, not one of fifty two
839 // so the added entropy for that card is only one bit at most
840 if (entropy.base.asInt == 52) {
841 var totalCombos = factorial(52);
842 var remainingCards = 52 - entropy.base.parts.length;
843 var remainingCombos = factorial(remainingCards);
844 var currentCombos = totalCombos.divide(remainingCombos);
845 bitsStr = currentCombos.toString(2).length.toString();
846 }
847 return bitsStr
848 }
849
850 // Depends on BigInteger
851 function factorial(n) {
852 if (n == 0) {
853 return 1;
854 }
855 f = BigInteger.ONE;
856 for (var i=1; i<=n; i++) {
857 f = f.multiply(new BigInteger(i));
858 }
859 return f;
860 }
861
833 var networks = [ 862 var networks = [
834 { 863 {
835 name: "Bitcoin", 864 name: "Bitcoin",