aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorIan Coleman <coleman.ian@gmail.com>2016-11-07 16:56:44 +1100
committerIan Coleman <coleman.ian@gmail.com>2016-11-07 16:56:44 +1100
commit425b75a925717eb6f9813503569592a8160c5f34 (patch)
tree3dcc83e4c88b0a68eaff3bc1724c07093608e4e5 /src/js
parentadc8ce127d4f8ea0d7e5ede6a82c2791d60ff4d2 (diff)
downloadBIP39-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
Diffstat (limited to 'src/js')
-rw-r--r--src/js/entropy.js7
1 files changed, 4 insertions, 3 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;