X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Fentropy.js;h=0b76dcfef0afbdfb8f8de5103bb090828718fa9f;hb=b54c12180e5f4eb633e587551715707ec0523943;hp=8e29d40824237365b41dd543d21b5e90f91f78ab;hpb=425b75a925717eb6f9813503569592a8160c5f34;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/entropy.js b/src/js/entropy.js index 8e29d40..0b76dcf 100644 --- a/src/js/entropy.js +++ b/src/js/entropy.js @@ -70,19 +70,22 @@ window.Entropy = new (function() { // 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 -1) { - newRawEntropyStr += c; + newParts[i] = base.parts[i]; + newInts[i] = base.ints[i]; } else { - newRawEntropyStr += "0"; + newParts[i] = "0"; + newInts[i] = 0; } } - rawEntropyStr = newRawEntropyStr; base.str = "base 6 (dice)"; - base.parts = matchers.base6(rawEntropyStr); + base.ints = newInts; + base.parts = newParts; base.matcher = matchers.base6; } // Detect empty entropy @@ -90,45 +93,10 @@ window.Entropy = new (function() { return { binaryStr: "", cleanStr: "", + cleanHtml: "", base: base, }; } - // Pull leading zeros off - var leadingZeros = []; - while (base.ints[0] == "0") { - leadingZeros.push("0"); - base.ints.shift(); - } - // Convert leading zeros to binary equivalent - var numBinLeadingZeros = Math.floor(Math.log2(base.asInt) * leadingZeros.length); - var binLeadingZeros = ""; - for (var i=0; i\u2663"); + entropyHtml = entropyHtml.replace(/D/g, "\u2666"); + entropyHtml = entropyHtml.replace(/H/g, "\u2665"); + entropyHtml = entropyHtml.replace(/S/g, "\u2660"); + } var e = { binaryStr: entropyBin, cleanStr: entropyClean, + cleanHtml: entropyHtml, base: base, } return e;