X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=f354399cc2d09130601cc1d1136fd07297cf99ae;hb=95f04905c13775e00c8dc13f884a17a4e69aaf29;hp=e064185f411124f18f78316ca72114b5fc24898d;hpb=391c7f267f6be3356d0bffa74e2726245b5f45b2;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index e064185..f354399 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -810,13 +810,20 @@ // If time to crack is less than one day, and password is considered // strong or better based on the number of bits, rename strength to // 'easily cracked'. - var z = zxcvbn(entropy.cleanStr); - var timeToCrack = z.crack_times_seconds.offline_fast_hashing_1e10_per_second; - if (timeToCrack < 86400 && entropy.binaryStr.length >= 128) { - strength = "easily cracked"; - if (z.feedback.warning != "") { - strength = strength + " - " + z.feedback.warning; - }; + try { + var z = zxcvbn(entropy.base.parts.join("")); + var timeToCrack = z.crack_times_seconds.offline_fast_hashing_1e10_per_second; + if (timeToCrack < 86400 && entropy.binaryStr.length >= 128) { + strength = "easily cracked"; + if (z.feedback.warning != "") { + strength = strength + " - " + z.feedback.warning; + }; + } + } + catch (e) { + strength = "unknown"; + console.log("Error detecting entropy strength with zxcvbn:"); + console.log(e); } var bitsStr = getNumberOfEntropyBits(entropy); var wordCount = Math.floor(entropy.binaryStr.length / 32) * 3; @@ -839,9 +846,13 @@ // eg the second last card can be only one of two, not one of fifty two // so the added entropy for that card is only one bit at most if (entropy.base.asInt == 52) { - var totalCombos = factorial(52); - var remainingCards = 52 - entropy.base.parts.length; - var remainingCombos = factorial(remainingCards); + var totalDecks = Math.ceil(entropy.base.parts.length / 52); + var totalCards = totalDecks * 52; + var totalCombos = factorial(52).pow(totalDecks); + var totalRemainingCards = totalCards - entropy.base.parts.length; + var remainingDecks = Math.floor(totalRemainingCards / 52); + var remainingCards = totalRemainingCards % 52; + var remainingCombos = factorial(52).pow(remainingDecks) * factorial(remainingCards); var currentCombos = totalCombos.divide(remainingCombos); bitsStr = currentCombos.toString(2).length.toString(); }