diff options
-rw-r--r-- | bip39-standalone.html | 7 | ||||
-rw-r--r-- | src/js/entropy.js | 7 | ||||
-rw-r--r-- | tests.js | 59 |
3 files changed, 65 insertions, 8 deletions
diff --git a/bip39-standalone.html b/bip39-standalone.html index 4bad422..0da2443 100644 --- a/bip39-standalone.html +++ b/bip39-standalone.html | |||
@@ -18467,7 +18467,12 @@ window.Entropy = new (function() { | |||
18467 | } | 18467 | } |
18468 | // Work out the total number of bits for this many decks | 18468 | // Work out the total number of bits for this many decks |
18469 | // See http://crypto.stackexchange.com/q/41886 | 18469 | // See http://crypto.stackexchange.com/q/41886 |
18470 | var gainedBits = Math.log2(factorial(52 * numberOfDecks)); | 18470 | var gainedBits = 0; |
18471 | // Equivalent of Math.log2(factorial(52*numberOfDecks)) | ||
18472 | // which becomes infinity for numberOfDecks > 4 | ||
18473 | for (var i=1; i<=52*numberOfDecks; i++) { | ||
18474 | gainedBits = gainedBits + Math.log2(i); | ||
18475 | } | ||
18471 | var lostBits = 52 * Math.log2(factorial(numberOfDecks)); | 18476 | var lostBits = 52 * Math.log2(factorial(numberOfDecks)); |
18472 | var maxBits = gainedBits - lostBits; | 18477 | var maxBits = gainedBits - lostBits; |
18473 | // Convert the drawn cards to a binary representation. | 18478 | // Convert the drawn cards to a binary representation. |
diff --git a/src/js/entropy.js b/src/js/entropy.js index b7274bb..24fc21a 100644 --- a/src/js/entropy.js +++ b/src/js/entropy.js | |||
@@ -263,7 +263,12 @@ window.Entropy = new (function() { | |||
263 | } | 263 | } |
264 | // Work out the total number of bits for this many decks | 264 | // Work out the total number of bits for this many decks |
265 | // See http://crypto.stackexchange.com/q/41886 | 265 | // See http://crypto.stackexchange.com/q/41886 |
266 | var gainedBits = Math.log2(factorial(52 * numberOfDecks)); | 266 | var gainedBits = 0; |
267 | // Equivalent of Math.log2(factorial(52*numberOfDecks)) | ||
268 | // which becomes infinity for numberOfDecks > 4 | ||
269 | for (var i=1; i<=52*numberOfDecks; i++) { | ||
270 | gainedBits = gainedBits + Math.log2(i); | ||
271 | } | ||
267 | var lostBits = 52 * Math.log2(factorial(numberOfDecks)); | 272 | var lostBits = 52 * Math.log2(factorial(numberOfDecks)); |
268 | var maxBits = gainedBits - lostBits; | 273 | var maxBits = gainedBits - lostBits; |
269 | // Convert the drawn cards to a binary representation. | 274 | // Convert the drawn cards to a binary representation. |
@@ -2726,6 +2726,50 @@ page.open(url, function(status) { | |||
2726 | words: 18, | 2726 | words: 18, |
2727 | strength: "extremely strong", | 2727 | strength: "extremely strong", |
2728 | }, | 2728 | }, |
2729 | // Multiple decks of cards increases bits per event | ||
2730 | { | ||
2731 | entropy: "3d", | ||
2732 | events: 1, | ||
2733 | bits: 4, | ||
2734 | bitsPerEvent: 4.34, | ||
2735 | }, | ||
2736 | { | ||
2737 | entropy: "3d3d", | ||
2738 | events: 2, | ||
2739 | bits: 9, | ||
2740 | bitsPerEvent: 4.80, | ||
2741 | }, | ||
2742 | { | ||
2743 | entropy: "3d3d3d", | ||
2744 | events: 3, | ||
2745 | bits: 15, | ||
2746 | bitsPerEvent: 5.01, | ||
2747 | }, | ||
2748 | { | ||
2749 | entropy: "3d3d3d3d", | ||
2750 | events: 4, | ||
2751 | bits: 20, | ||
2752 | bitsPerEvent: 5.14, | ||
2753 | }, | ||
2754 | { | ||
2755 | entropy: "3d3d3d3d3d", | ||
2756 | events: 5, | ||
2757 | bits: 26, | ||
2758 | bitsPerEvent: 5.22, | ||
2759 | }, | ||
2760 | { | ||
2761 | entropy: "3d3d3d3d3d3d", | ||
2762 | events: 6, | ||
2763 | bits: 31, | ||
2764 | bitsPerEvent: 5.28, | ||
2765 | }, | ||
2766 | { | ||
2767 | entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d", | ||
2768 | events: 33, | ||
2769 | bits: 184, | ||
2770 | bitsPerEvent: 5.59, | ||
2771 | strength: 'easily cracked - Repeats like "abcabcabc" are only slightly harder to guess than "abc"', | ||
2772 | }, | ||
2729 | ]; | 2773 | ]; |
2730 | // use entropy | 2774 | // use entropy |
2731 | page.evaluate(function() { | 2775 | page.evaluate(function() { |
@@ -2737,18 +2781,21 @@ page.open(url, function(status) { | |||
2737 | if ("filtered" in expected && actual.indexOf(expected.filtered) == -1) { | 2781 | if ("filtered" in expected && actual.indexOf(expected.filtered) == -1) { |
2738 | return "Filtered value not in feedback"; | 2782 | return "Filtered value not in feedback"; |
2739 | } | 2783 | } |
2740 | if (actual.indexOf(expected.type) == -1) { | 2784 | if ("type" in expected && actual.indexOf(expected.type) == -1) { |
2741 | return "Entropy type not in feedback"; | 2785 | return "Entropy type not in feedback"; |
2742 | } | 2786 | } |
2743 | if (actual.indexOf(expected.events) == -1) { | 2787 | if ("events" in expected && actual.indexOf(expected.events) == -1) { |
2744 | return "Event count not in feedback"; | 2788 | return "Event count not in feedback"; |
2745 | } | 2789 | } |
2746 | if (actual.indexOf(expected.bits) == -1) { | 2790 | if ("bits" in expected && actual.indexOf(expected.bits) == -1) { |
2747 | return "Bit count not in feedback"; | 2791 | return "Bit count not in feedback"; |
2748 | } | 2792 | } |
2749 | if (actual.indexOf(expected.strength) == -1) { | 2793 | if ("strength" in expected && actual.indexOf(expected.strength) == -1) { |
2750 | return "Strength not in feedback"; | 2794 | return "Strength not in feedback"; |
2751 | } | 2795 | } |
2796 | if ("bitsPerEvent" in expected && actual.indexOf(expected.bitsPerEvent) == -1) { | ||
2797 | return "bitsPerEvent not in feedback"; | ||
2798 | } | ||
2752 | return false; | 2799 | return false; |
2753 | } | 2800 | } |
2754 | test = tests[i]; | 2801 | test = tests[i]; |
@@ -2762,7 +2809,7 @@ page.open(url, function(status) { | |||
2762 | return $(".phrase").val(); | 2809 | return $(".phrase").val(); |
2763 | }); | 2810 | }); |
2764 | // Check mnemonic length | 2811 | // Check mnemonic length |
2765 | if (test.words == 0) { | 2812 | if ("words" in test && test.words == 0) { |
2766 | if (mnemonic.length > 0) { | 2813 | if (mnemonic.length > 0) { |
2767 | console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); | 2814 | console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); |
2768 | console.log("Entropy: " + test.entropy); | 2815 | console.log("Entropy: " + test.entropy); |
@@ -2770,7 +2817,7 @@ page.open(url, function(status) { | |||
2770 | fail(); | 2817 | fail(); |
2771 | } | 2818 | } |
2772 | } | 2819 | } |
2773 | else { | 2820 | else if ("words" in test) { |
2774 | if (mnemonic.split(" ").length != test.words) { | 2821 | if (mnemonic.split(" ").length != test.words) { |
2775 | console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); | 2822 | console.log("Mnemonic length for " + test.strength + " strength is not " + test.words); |
2776 | console.log("Entropy: " + test.entropy); | 2823 | console.log("Entropy: " + test.entropy); |