diff options
author | Ian Coleman <coleman.ian@gmail.com> | 2016-11-07 16:56:44 +1100 |
---|---|---|
committer | Ian Coleman <coleman.ian@gmail.com> | 2016-11-07 16:56:44 +1100 |
commit | 425b75a925717eb6f9813503569592a8160c5f34 (patch) | |
tree | 3dcc83e4c88b0a68eaff3bc1724c07093608e4e5 | |
parent | adc8ce127d4f8ea0d7e5ede6a82c2791d60ff4d2 (diff) | |
download | BIP39-425b75a925717eb6f9813503569592a8160c5f34.tar.gz BIP39-425b75a925717eb6f9813503569592a8160c5f34.tar.zst BIP39-425b75a925717eb6f9813503569592a8160c5f34.zip |
Dice entropy conversion to Base 6 is simpler
Old: Every dice roll is reduced by 1
New: Replace all 6s with 0s
-rw-r--r-- | src/js/entropy.js | 7 | ||||
-rw-r--r-- | tests.js | 4 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/js/entropy.js b/src/js/entropy.js index 92300af..8e29d40 100644 --- a/src/js/entropy.js +++ b/src/js/entropy.js | |||
@@ -68,15 +68,16 @@ window.Entropy = new (function() { | |||
68 | // Find type of entropy being used (binary, hex, dice etc) | 68 | // Find type of entropy being used (binary, hex, dice etc) |
69 | var base = getBase(rawEntropyStr); | 69 | var base = getBase(rawEntropyStr); |
70 | // Convert dice to base6 entropy (ie 1-6 to 0-5) | 70 | // Convert dice to base6 entropy (ie 1-6 to 0-5) |
71 | // This is done by changing all 6s to 0s | ||
71 | if (base.str == "dice") { | 72 | if (base.str == "dice") { |
72 | var newRawEntropyStr = ""; | 73 | var newRawEntropyStr = ""; |
73 | for (var i=0; i<rawEntropyStr.length; i++) { | 74 | for (var i=0; i<rawEntropyStr.length; i++) { |
74 | var c = rawEntropyStr[i]; | 75 | var c = rawEntropyStr[i]; |
75 | if ("123456".indexOf(c) > -1) { | 76 | if ("12345".indexOf(c) > -1) { |
76 | newRawEntropyStr += (parseInt(c) - 1).toString(); | 77 | newRawEntropyStr += c; |
77 | } | 78 | } |
78 | else { | 79 | else { |
79 | newRawEntropyStr += c | 80 | newRawEntropyStr += "0"; |
80 | } | 81 | } |
81 | } | 82 | } |
82 | rawEntropyStr = newRawEntropyStr; | 83 | rawEntropyStr = newRawEntropyStr; |
@@ -2072,7 +2072,7 @@ page.open(url, function(status) { | |||
2072 | // dice entropy is converted to base6 | 2072 | // dice entropy is converted to base6 |
2073 | try { | 2073 | try { |
2074 | e = Entropy.fromString("123456"); | 2074 | e = Entropy.fromString("123456"); |
2075 | if (e.cleanStr != "012345") { | 2075 | if (e.cleanStr != "123450") { |
2076 | return "Dice entropy is not automatically converted to base6"; | 2076 | return "Dice entropy is not automatically converted to base6"; |
2077 | } | 2077 | } |
2078 | } | 2078 | } |
@@ -2444,7 +2444,7 @@ page.open(url, function(status) { | |||
2444 | var entropyText = page.evaluate(function() { | 2444 | var entropyText = page.evaluate(function() { |
2445 | return $(".entropy-container").text(); | 2445 | return $(".entropy-container").text(); |
2446 | }); | 2446 | }); |
2447 | if (entropyText.indexOf("012345") == -1) { | 2447 | if (entropyText.indexOf("123450") == -1) { |
2448 | console.log("Dice entropy is not shown to user as base 6 value"); | 2448 | console.log("Dice entropy is not shown to user as base 6 value"); |
2449 | fail(); | 2449 | fail(); |
2450 | } | 2450 | } |