]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Dice entropy conversion to Base 6 is simpler
authorIan Coleman <coleman.ian@gmail.com>
Mon, 7 Nov 2016 05:56:44 +0000 (16:56 +1100)
committerIan Coleman <coleman.ian@gmail.com>
Mon, 7 Nov 2016 05:56:44 +0000 (16:56 +1100)
Old: Every dice roll is reduced by 1
New: Replace all 6s with 0s

src/js/entropy.js
tests.js

index 92300afa352f27b48a1f600705fe5e04fe1383bc..8e29d40824237365b41dd543d21b5e90f91f78ab 100644 (file)
@@ -68,15 +68,16 @@ window.Entropy = new (function() {
         // Find type of entropy being used (binary, hex, dice etc)
         var base = getBase(rawEntropyStr);
         // Convert dice to base6 entropy (ie 1-6 to 0-5)
+        // This is done by changing all 6s to 0s
         if (base.str == "dice") {
             var newRawEntropyStr = "";
             for (var i=0; i<rawEntropyStr.length; i++) {
                 var c = rawEntropyStr[i];
-                if ("123456".indexOf(c) > -1) {
-                    newRawEntropyStr += (parseInt(c) - 1).toString();
+                if ("12345".indexOf(c) > -1) {
+                    newRawEntropyStr += c;
                 }
                 else {
-                    newRawEntropyStr += c
+                    newRawEntropyStr += "0";
                 }
             }
             rawEntropyStr = newRawEntropyStr;
index 8de6391fd7bb0aafe6b9317d9c2b46285998bb2c..809162cac7a3f3824b3ee21e6b00e14c61007d88 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -2072,7 +2072,7 @@ page.open(url, function(status) {
         // dice entropy is converted to base6
         try {
             e = Entropy.fromString("123456");
-            if (e.cleanStr != "012345") {
+            if (e.cleanStr != "123450") {
                 return "Dice entropy is not automatically converted to base6";
             }
         }
@@ -2444,7 +2444,7 @@ page.open(url, function(status) {
         var entropyText = page.evaluate(function() {
             return $(".entropy-container").text();
         });
-        if (entropyText.indexOf("012345") == -1) {
+        if (entropyText.indexOf("123450") == -1) {
             console.log("Dice entropy is not shown to user as base 6 value");
             fail();
         }