Remove bias from entropy in base 6 and base 10

This commit is contained in:
Ian Coleman
2020-10-01 23:44:38 +00:00
parent 920f7aa078
commit bf96267f89
4 changed files with 216 additions and 235 deletions
+1 -1
View File
@@ -86,7 +86,7 @@
<div class="row"> <div class="row">
<label class="col-sm-3 control-label">Entropy Type</label> <label class="col-sm-3 control-label">Entropy Type</label>
<div class="type col-sm-3 form-control-static"></div> <div class="type col-sm-3 form-control-static"></div>
<label class="col-sm-3 control-label">Bits Per Event</label> <label class="col-sm-3 control-label">Avg Bits Per Event</label>
<div class="bits-per-event col-sm-3 form-control-static"></div> <div class="bits-per-event col-sm-3 form-control-static"></div>
</div> </div>
<div class="row"> <div class="row">
+160 -185
View File
@@ -16,7 +16,136 @@
window.Entropy = new (function() { window.Entropy = new (function() {
var TWO = new libs.BigInteger.BigInteger(2); let eventBits = {
"binary": {
"0": "0",
"1": "1",
},
// log2(6) = 2.58496 bits per roll, with bias
// 4 rolls give 2 bits each
// 2 rolls give 1 bit each
// Average (4*2 + 2*1) / 6 = 1.66 bits per roll without bias
"base 6": {
"0": "00",
"1": "01",
"2": "10",
"3": "11",
"4": "0",
"5": "1",
},
// log2(6) = 2.58496 bits per roll, with bias
// 4 rolls give 2 bits each
// 2 rolls give 1 bit each
// Average (4*2 + 2*1) / 6 = 1.66 bits per roll without bias
"base 6 (dice)": {
"0": "00", // equivalent to 0 in base 6
"1": "01",
"2": "10",
"3": "11",
"4": "0",
"5": "1",
},
// log2(10) = 3.321928 bits per digit, with bias
// 8 digits give 3 bits each
// 2 digits give 1 bit each
// Average (8*3 + 2*1) / 10 = 2.6 bits per digit without bias
"base 10": {
"0": "000",
"1": "001",
"2": "010",
"3": "011",
"4": "100",
"5": "101",
"6": "110",
"7": "111",
"8": "0",
"9": "1",
},
"hexadecimal": {
"0": "0000",
"1": "0001",
"2": "0010",
"3": "0011",
"4": "0100",
"5": "0101",
"6": "0110",
"7": "0111",
"8": "1000",
"9": "1001",
"a": "1010",
"b": "1011",
"c": "1100",
"d": "1101",
"e": "1110",
"f": "1111",
},
// log2(52) = 5.7004 bits per card, with bias
// 32 cards give 5 bits each
// 16 cards give 4 bits each
// 4 cards give 2 bits each
// Average (32*5 + 16*4 + 4*2) / 52 = 4.46 bits per card without bias
"card": {
"ac": "00000",
"2c": "00001",
"3c": "00010",
"4c": "00011",
"5c": "00100",
"6c": "00101",
"7c": "00110",
"8c": "00111",
"9c": "01000",
"tc": "01001",
"jc": "01010",
"qc": "01011",
"kc": "01100",
"ad": "01101",
"2d": "01110",
"3d": "01111",
"4d": "10000",
"5d": "10001",
"6d": "10010",
"7d": "10011",
"8d": "10100",
"9d": "10101",
"td": "10110",
"jd": "10111",
"qd": "11000",
"kd": "11001",
"ah": "11010",
"2h": "11011",
"3h": "11100",
"4h": "11101",
"5h": "11110",
"6h": "11111",
"7h": "0000",
"8h": "0001",
"9h": "0010",
"th": "0011",
"jh": "0100",
"qh": "0101",
"kh": "0110",
"as": "0111",
"2s": "1000",
"3s": "1001",
"4s": "1010",
"5s": "1011",
"6s": "1100",
"7s": "1101",
"8s": "1110",
"9s": "1111",
"ts": "00",
"js": "01",
"qs": "10",
"ks": "11",
},
}
// matchers returns an array of the matched events for each type of entropy. // matchers returns an array of the matched events for each type of entropy.
// eg // eg
@@ -51,48 +180,28 @@ window.Entropy = new (function() {
} }
} }
// Convert array of cards from ["ac", "4d", "ks"]
// to numbers between 0 and 51 [0, 16, 51]
function convertCardsToInts(cards) {
var ints = [];
var values = "a23456789tjqk";
var suits = "cdhs";
for (var i=0; i<cards.length; i++) {
var card = cards[i].toLowerCase();
var value = card[0];
var suit = card[1];
var asInt = 13 * suits.indexOf(suit) + values.indexOf(value);
ints.push(asInt);
}
return ints;
}
this.fromString = function(rawEntropyStr, baseStr) { this.fromString = function(rawEntropyStr, baseStr) {
// Find type of entropy being used (binary, hex, dice etc) // Find type of entropy being used (binary, hex, dice etc)
var base = getBase(rawEntropyStr, baseStr); var base = getBase(rawEntropyStr, baseStr);
// Convert dice to base6 entropy (ie 1-6 to 0-5) // Convert dice to base6 entropy (ie 1-6 to 0-5)
// This is done by changing all 6s to 0s // This is done by changing all 6s to 0s
if (base.str == "dice") { if (base.str == "dice") {
var newParts = []; var newEvents = [];
var newInts = []; for (var i=0; i<base.events.length; i++) {
for (var i=0; i<base.parts.length; i++) { var c = base.events[i];
var c = base.parts[i];
if ("12345".indexOf(c) > -1) { if ("12345".indexOf(c) > -1) {
newParts[i] = base.parts[i]; newEvents[i] = base.events[i];
newInts[i] = base.ints[i];
} }
else { else {
newParts[i] = "0"; newEvents[i] = "0";
newInts[i] = 0;
} }
} }
base.str = "base 6 (dice)"; base.str = "base 6 (dice)";
base.ints = newInts; base.events = newEvents;
base.parts = newParts;
base.matcher = matchers.base6; base.matcher = matchers.base6;
} }
// Detect empty entropy // Detect empty entropy
if (base.parts.length == 0) { if (base.events.length == 0) {
return { return {
binaryStr: "", binaryStr: "",
cleanStr: "", cleanStr: "",
@@ -100,44 +209,23 @@ window.Entropy = new (function() {
base: base, base: base,
}; };
} }
// Convert base.ints to BigInteger. // Convert entropy events to binary
// Due to using unusual bases, eg cards of base52, this is not as simple as var entropyBin = base.events.map(function(e) {
// using BigInteger.parse() return eventBits[base.str][e.toLowerCase()];
var entropyInt = libs.BigInteger.BigInteger.ZERO; }).join("");
for (var i=base.ints.length-1; i>=0; i--) { // Get average bits per event
var thisInt = libs.BigInteger.BigInteger.parse(base.ints[i]); // which may be adjusted for bias if log2(base) is fractional
var power = (base.ints.length - 1) - i; var bitsPerEvent = base.bitsPerEvent;
var additionalEntropy = libs.BigInteger.BigInteger.parse(base.asInt).pow(power).multiply(thisInt);
entropyInt = entropyInt.add(additionalEntropy);
}
// Convert entropy to binary
var entropyBin = entropyInt.toString(2);
// If the first integer is small, it must be padded with zeros.
// Otherwise the chance of the first bit being 1 is 100%, which is
// obviously incorrect.
// This is not perfect for non-2^n bases.
var expectedBits = Math.floor(base.parts.length * Math.log2(base.asInt));
while (entropyBin.length < expectedBits) {
entropyBin = "0" + entropyBin;
}
// Calculate the number of bits per event
var bitsPerEvent = Math.log2(base.asInt);
// Cards binary must be handled differently, since they're not replaced
if (base.asInt == 52) {
var cardEntropy = processCardEntropy(base.parts);
entropyBin = cardEntropy.binaryStr;
bitsPerEvent = cardEntropy.bitsPerEvent;
}
// Supply a 'filtered' entropy string for display purposes // Supply a 'filtered' entropy string for display purposes
var entropyClean = base.parts.join(""); var entropyClean = base.events.join("");
var entropyHtml = base.parts.join(""); var entropyHtml = base.events.join("");
if (base.asInt == 52) { if (base.asInt == 52) {
entropyClean = base.parts.join(" ").toUpperCase(); entropyClean = base.events.join(" ").toUpperCase();
entropyClean = entropyClean.replace(/C/g, "\u2663"); entropyClean = entropyClean.replace(/C/g, "\u2663");
entropyClean = entropyClean.replace(/D/g, "\u2666"); entropyClean = entropyClean.replace(/D/g, "\u2666");
entropyClean = entropyClean.replace(/H/g, "\u2665"); entropyClean = entropyClean.replace(/H/g, "\u2665");
entropyClean = entropyClean.replace(/S/g, "\u2660"); entropyClean = entropyClean.replace(/S/g, "\u2660");
entropyHtml = base.parts.join(" ").toUpperCase(); entropyHtml = base.events.join(" ").toUpperCase();
entropyHtml = entropyHtml.replace(/C/g, "<span class='card-suit club'>\u2663</span>"); entropyHtml = entropyHtml.replace(/C/g, "<span class='card-suit club'>\u2663</span>");
entropyHtml = entropyHtml.replace(/D/g, "<span class='card-suit diamond'>\u2666</span>"); entropyHtml = entropyHtml.replace(/D/g, "<span class='card-suit diamond'>\u2666</span>");
entropyHtml = entropyHtml.replace(/H/g, "<span class='card-suit heart'>\u2665</span>"); entropyHtml = entropyHtml.replace(/H/g, "<span class='card-suit heart'>\u2665</span>");
@@ -154,18 +242,6 @@ window.Entropy = new (function() {
return e; return e;
} }
function getSortedDeck() {
var s = [];
var suits = "CDHS";
var values = "A23456789TJQK";
for (var i=0; i<suits.length; i++) {
for (var j=0; j<values.length; j++) {
s.push(values[j]+suits[i]);
}
}
return s;
}
function getBase(str, baseStr) { function getBase(str, baseStr) {
// Need to get the lowest base for the supplied entropy. // Need to get the lowest base for the supplied entropy.
// This prevents interpreting, say, dice rolls as hexadecimal. // This prevents interpreting, say, dice rolls as hexadecimal.
@@ -177,20 +253,21 @@ window.Entropy = new (function() {
var ints = binaryMatches.map(function(i) { return parseInt(i, 2) }); var ints = binaryMatches.map(function(i) { return parseInt(i, 2) });
return { return {
ints: ints, ints: ints,
parts: binaryMatches, events: binaryMatches,
matcher: matchers.binary, matcher: matchers.binary,
asInt: 2, asInt: 2,
bitsPerEvent: 1,
str: "binary", str: "binary",
} }
} }
var cardMatches = matchers.card(str); var cardMatches = matchers.card(str);
if ((cardMatches.length >= hexMatches.length / 2 && autodetect) || baseStr === "card") { if ((cardMatches.length >= hexMatches.length / 2 && autodetect) || baseStr === "card") {
var ints = convertCardsToInts(cardMatches);
return { return {
ints: ints, ints: ints,
parts: cardMatches, events: cardMatches,
matcher: matchers.card, matcher: matchers.card,
asInt: 52, asInt: 52,
bitsPerEvent: (32*5 + 16*4 + 4*2) / 52, // see cardBits
str: "card", str: "card",
} }
} }
@@ -199,9 +276,10 @@ window.Entropy = new (function() {
var ints = diceMatches.map(function(i) { return parseInt(i) }); var ints = diceMatches.map(function(i) { return parseInt(i) });
return { return {
ints: ints, ints: ints,
parts: diceMatches, events: diceMatches,
matcher: matchers.dice, matcher: matchers.dice,
asInt: 6, asInt: 6,
bitsPerEvent: (4*2 + 2*1) / 6, // see diceBits
str: "dice", str: "dice",
} }
} }
@@ -210,9 +288,10 @@ window.Entropy = new (function() {
var ints = base6Matches.map(function(i) { return parseInt(i) }); var ints = base6Matches.map(function(i) { return parseInt(i) });
return { return {
ints: ints, ints: ints,
parts: base6Matches, events: base6Matches,
matcher: matchers.base6, matcher: matchers.base6,
asInt: 6, asInt: 6,
bitsPerEvent: (4*2 + 2*1) / 6, // see diceBits
str: "base 6", str: "base 6",
} }
} }
@@ -221,126 +300,22 @@ window.Entropy = new (function() {
var ints = base10Matches.map(function(i) { return parseInt(i) }); var ints = base10Matches.map(function(i) { return parseInt(i) });
return { return {
ints: ints, ints: ints,
parts: base10Matches, events: base10Matches,
matcher: matchers.base10, matcher: matchers.base10,
asInt: 10, asInt: 10,
bitsPerEvent: (8*3 + 2*1) / 10, // see b10Bits
str: "base 10", str: "base 10",
} }
} }
var ints = hexMatches.map(function(i) { return parseInt(i, 16) }); var ints = hexMatches.map(function(i) { return parseInt(i, 16) });
return { return {
ints: ints, ints: ints,
parts: hexMatches, events: hexMatches,
matcher: matchers.hex, matcher: matchers.hex,
asInt: 16, asInt: 16,
bitsPerEvent: 4,
str: "hexadecimal", str: "hexadecimal",
} }
} }
// Assume cards are NOT replaced.
// Additional entropy decreases as more cards are used. This means
// total possible entropy is measured using n!, not base^n.
// 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
function processCardEntropy(cards) {
// Track how many instances of each card have been used, and thus
// how many decks are in use.
var cardCounts = {};
var numberOfDecks = 0;
// Work out number of decks by max(duplicates)
for (var i=0; i<cards.length; i++) {
// Get the card that was drawn
var cardLower = cards[i];
var card = cardLower.toUpperCase();
// Initialize the count for this card if needed
if (!(card in cardCounts)) {
cardCounts[card] = 0;
}
cardCounts[card] += 1;
// See if this is max(duplicates)
if (cardCounts[card] > numberOfDecks) {
numberOfDecks = cardCounts[card];
}
}
// Work out the total number of bits for this many decks
// See http://crypto.stackexchange.com/q/41886
var gainedBits = 0;
// Equivalent of Math.log2(factorial(52*numberOfDecks))
// which becomes infinity for numberOfDecks > 4
for (var i=1; i<=52*numberOfDecks; i++) {
gainedBits = gainedBits + Math.log2(i);
}
var lostBits = 52 * Math.log2(factorial(numberOfDecks));
var maxBits = gainedBits - lostBits;
// Convert the drawn cards to a binary representation.
// The exact technique for doing this is unclear.
// See
// http://crypto.stackexchange.com/a/41896
// "I even doubt that this is well defined (only the average entropy
// is, I believe)."
// See
// https://github.com/iancoleman/bip39/issues/33#issuecomment-263021856
// "The binary representation can be the first log(permutations,2) bits
// of the sha-2 hash of the normalized deck string."
//
// In this specific implementation, the first N bits of the hash of the
// normalized cards string is being used. Uppercase, no spaces; eg
// sha256("AH8DQSTC2H")
var totalCards = numberOfDecks * 52;
var percentUsed = cards.length / totalCards;
// Calculate the average number of bits of entropy for the number of
// cards drawn.
var numberOfBits = Math.floor(maxBits * percentUsed);
// Create a normalized string of the selected cards
var normalizedCards = cards.join("").toUpperCase();
// Convert to binary using the SHA256 hash of the normalized cards.
// If the number of bits is more than 256, multiple hashes
// are used until the required number of bits is reached.
var entropyBin = "";
var iterations = 0;
while (entropyBin.length < numberOfBits) {
var hashedCards = sjcl.hash.sha256.hash(normalizedCards + ":" + iterations);
var hashHex = sjcl.codec.hex.fromBits(hashedCards);
for (var i=0; i<hashHex.length; i++) {
var decimal = parseInt(hashHex[i], 16);
var binary = decimal.toString(2);
while (binary.length < 4) {
binary = "0" + binary;
}
entropyBin = entropyBin + binary;
}
iterations = iterations + 1;
}
// Truncate to the appropriate number of bits.
entropyBin = entropyBin.substring(0, numberOfBits);
// Get the number of bits per event
bitsPerEvent = maxBits / totalCards;
return {
binaryStr: entropyBin,
bitsPerEvent: bitsPerEvent,
}
}
// Polyfill for Math.log2
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/log2#Polyfill
Math.log2 = Math.log2 || function(x) {
// The polyfill isn't good enough because of the poor accuracy of
// Math.LOG2E
// log2(8) gave 2.9999999999999996 which when floored causes issues.
// So instead use the BigInteger library to get it right.
return libs.BigInteger.BigInteger.log(x) / libs.BigInteger.BigInteger.log(2);
};
// Depends on BigInteger
function factorial(n) {
if (n == 0) {
return 1;
}
f = libs.BigInteger.BigInteger.ONE;
for (var i=1; i<=n; i++) {
f = f.multiply(new libs.BigInteger.BigInteger(i));
}
return f;
}
})(); })();
+4 -4
View File
@@ -1726,7 +1726,7 @@
var numberOfBits = entropy.binaryStr.length; var numberOfBits = entropy.binaryStr.length;
var timeToCrack = "unknown"; var timeToCrack = "unknown";
try { try {
var z = libs.zxcvbn(entropy.base.parts.join("")); var z = libs.zxcvbn(entropy.base.events.join(""));
timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second; timeToCrack = z.crack_times_display.offline_fast_hashing_1e10_per_second;
if (z.feedback.warning != "") { if (z.feedback.warning != "") {
timeToCrack = timeToCrack + " - " + z.feedback.warning; timeToCrack = timeToCrack + " - " + z.feedback.warning;
@@ -1745,7 +1745,7 @@
DOM.entropyFiltered.html(entropy.cleanHtml); DOM.entropyFiltered.html(entropy.cleanHtml);
DOM.entropyType.text(entropyTypeStr); DOM.entropyType.text(entropyTypeStr);
DOM.entropyCrackTime.text(timeToCrack); DOM.entropyCrackTime.text(timeToCrack);
DOM.entropyEventCount.text(entropy.base.ints.length); DOM.entropyEventCount.text(entropy.base.events.length);
DOM.entropyBits.text(numberOfBits); DOM.entropyBits.text(numberOfBits);
DOM.entropyWordCount.text(wordCount); DOM.entropyWordCount.text(wordCount);
DOM.entropyBinary.text(spacedBinaryStr); DOM.entropyBinary.text(spacedBinaryStr);
@@ -1770,8 +1770,8 @@
// Detect duplicates // Detect duplicates
var dupes = []; var dupes = [];
var dupeTracker = {}; var dupeTracker = {};
for (var i=0; i<entropy.base.parts.length; i++) { for (var i=0; i<entropy.base.events.length; i++) {
var card = entropy.base.parts[i]; var card = entropy.base.events[i];
var cardUpper = card.toUpperCase(); var cardUpper = card.toUpperCase();
if (cardUpper in dupeTracker) { if (cardUpper in dupeTracker) {
dupes.push(card); dupes.push(card);
+51 -45
View File
@@ -3120,7 +3120,7 @@ it("Shows the number of bits of entropy for 4 bits of binary", function(done) {
testEntropyBits(done, "0000", "4"); testEntropyBits(done, "0000", "4");
}); });
it("Shows the number of bits of entropy for 1 character of base 6 (dice)", function(done) { it("Shows the number of bits of entropy for 1 character of base 6 (dice)", function(done) {
// 6 in card is 0 in base 6, 0 in base 6 is 2.6 bits (rounded down to 2 bits) // 6 in card is 0 in base 6, 0 is mapped to 00 by entropy.js
testEntropyBits(done, "6", "2"); testEntropyBits(done, "6", "2");
}); });
it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits", function(done) { it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits", function(done) {
@@ -3128,13 +3128,15 @@ it("Shows the number of bits of entropy for 1 character of base 10 with 3 bits",
testEntropyBits(done, "7", "3"); testEntropyBits(done, "7", "3");
}); });
it("Shows the number of bits of entropy for 1 character of base 10 with 4 bis", function(done) { it("Shows the number of bits of entropy for 1 character of base 10 with 4 bis", function(done) {
testEntropyBits(done, "8", "4"); // 8 in base 10 is mapped to 0 by entropy.js
testEntropyBits(done, "8", "1");
}); });
it("Shows the number of bits of entropy for 1 character of hex", function(done) { it("Shows the number of bits of entropy for 1 character of hex", function(done) {
testEntropyBits(done, "F", "4"); testEntropyBits(done, "F", "4");
}); });
it("Shows the number of bits of entropy for 2 characters of base 10", function(done) { it("Shows the number of bits of entropy for 2 characters of base 10", function(done) {
testEntropyBits(done, "29", "6"); // 2 as base 10 is binary 010, 9 is mapped to binary 1 by entropy.js
testEntropyBits(done, "29", "4");
}); });
it("Shows the number of bits of entropy for 2 characters of hex", function(done) { it("Shows the number of bits of entropy for 2 characters of hex", function(done) {
testEntropyBits(done, "0A", "8"); testEntropyBits(done, "0A", "8");
@@ -3159,17 +3161,17 @@ it("Shows the number of bits of entropy for 4 characters of hex with leading zer
testEntropyBits(done, "000A", "16"); testEntropyBits(done, "000A", "16");
}); });
it("Shows the number of bits of entropy for 4 characters of base 6", function(done) { it("Shows the number of bits of entropy for 4 characters of base 6", function(done) {
testEntropyBits(done, "5555", "11"); // 5 in base 6 is mapped to binary 1
testEntropyBits(done, "5555", "4");
}); });
it("Shows the number of bits of entropy for 4 characters of base 6 dice", function(done) { it("Shows the number of bits of entropy for 4 characters of base 6 dice", function(done) {
// uses dice, so entropy is actually 0000 in base 6, which is 4 lots of // uses dice, so entropy is actually 0000 in base 6, which is 4 lots of
// 2.58 bits, which is 10.32 bits (rounded down to 10 bits) // binary 00
testEntropyBits(done, "6666", "10"); testEntropyBits(done, "6666", "8");
}); });
it("Shows the number of bits of entropy for 4 charactes of base 10", function(done) { it("Shows the number of bits of entropy for 4 charactes of base 10", function(done) {
// Uses base 10, which is 4 lots of 3.32 bits, which is 13.3 bits (rounded // 2 in base 10 is binary 010 and 7 is binary 111 so is 4 events of 3 bits
// down to 13) testEntropyBits(done, "2227", "12");
testEntropyBits(done, "2227", "13");
}); });
it("Shows the number of bits of entropy for 4 characters of hex with 2 leading zeros", function(done) { it("Shows the number of bits of entropy for 4 characters of hex with 2 leading zeros", function(done) {
testEntropyBits(done, "222F", "16"); testEntropyBits(done, "222F", "16");
@@ -3178,13 +3180,16 @@ it("Shows the number of bits of entropy for 4 characters of hex starting with F"
testEntropyBits(done, "FFFF", "16"); testEntropyBits(done, "FFFF", "16");
}); });
it("Shows the number of bits of entropy for 10 characters of base 10", function(done) { it("Shows the number of bits of entropy for 10 characters of base 10", function(done) {
// 10 events at 3.32 bits per event // 10 events with 3 bits for each event
testEntropyBits(done, "0000101017", "33"); testEntropyBits(done, "0000101017", "30");
});
it("Shows the number of bits of entropy for 10 characters of base 10 account for bias", function(done) {
// 9 events with 3 bits per event and 1 event with 1 bit per event
testEntropyBits(done, "0000101018", "28");
}); });
it("Shows the number of bits of entropy for a full deck of cards", function(done) { it("Shows the number of bits of entropy for a full deck of cards", function(done) {
// cards are not replaced, so a full deck is not 52^52 entropy which is 296 // removing bias is 32*5 + 16*4 + 4*2
// bits, it's 52!, which is 225 bits testEntropyBits(done, "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", "232");
testEntropyBits(done, "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", "225");
}); });
it("Shows details about the entered entropy", function(done) { it("Shows details about the entered entropy", function(done) {
@@ -3310,7 +3315,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "7d", entropy: "7d",
type: "card", type: "card",
events: "1", events: "1",
bits: "4", bits: "5",
words: 0, words: 0,
strength: "less than a second", strength: "less than a second",
} }
@@ -3322,7 +3327,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
type: "card (full deck)", type: "card (full deck)",
events: "52", events: "52",
bits: "225", bits: "232",
words: 21, words: 21,
strength: "centuries", strength: "centuries",
} }
@@ -3334,7 +3339,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d", entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks3d",
type: "card (full deck, 1 duplicate: 3d)", type: "card (full deck, 1 duplicate: 3d)",
events: "53", events: "53",
bits: "254", bits: "237",
words: 21, words: 21,
strength: "centuries", strength: "centuries",
} }
@@ -3346,7 +3351,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d", entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
type: "card (2 duplicates: 3d 4d, 1 missing: KS)", type: "card (2 duplicates: 3d 4d, 1 missing: KS)",
events: "53", events: "53",
bits: "254", bits: "240",
words: 21, words: 21,
strength: "centuries", strength: "centuries",
} }
@@ -3358,8 +3363,8 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d", entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)", type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)",
events: "55", events: "55",
bits: "264", bits: "250",
words: 24, words: 21,
strength: "centuries", strength: "centuries",
} }
); );
@@ -3367,13 +3372,12 @@ it("Shows details about the entered entropy", function(done) {
it("Shows details about the entered entropy", function(done) { it("Shows details about the entered entropy", function(done) {
testEntropyFeedback(done, testEntropyFeedback(done,
// Next test was throwing uncaught error in zxcvbn // Next test was throwing uncaught error in zxcvbn
// Also tests 451 bits, ie Math.log2(52!)*2 = 225.58 * 2
{ {
entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsksac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
type: "card (full deck, 52 duplicates: ac 2c 3c...)", type: "card (full deck, 52 duplicates: ac 2c 3c...)",
events: "104", events: "104",
bits: "499", bits: "464",
words: 45, words: 42,
strength: "centuries", strength: "centuries",
} }
); );
@@ -3385,7 +3389,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "asAS", entropy: "asAS",
type: "card (1 duplicate: AS)", type: "card (1 duplicate: AS)",
events: "2", events: "2",
bits: "9", bits: "8",
words: 0, words: 0,
strength: "less than a second", strength: "less than a second",
} }
@@ -3397,7 +3401,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ASas", entropy: "ASas",
type: "card (1 duplicate: as)", type: "card (1 duplicate: as)",
events: "2", events: "2",
bits: "9", bits: "8",
words: 0, words: 0,
strength: "less than a second", strength: "less than a second",
} }
@@ -3410,8 +3414,8 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
type: "card (1 missing: 9C)", type: "card (1 missing: 9C)",
events: "51", events: "51",
bits: "221", bits: "227",
words: 18, words: 21,
strength: "centuries", strength: "centuries",
} }
); );
@@ -3422,7 +3426,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
type: "card (2 missing: 9C 5D)", type: "card (2 missing: 9C 5D)",
events: "50", events: "50",
bits: "216", bits: "222",
words: 18, words: 18,
strength: "centuries", strength: "centuries",
} }
@@ -3434,7 +3438,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d7d8d9dtdjd kdah2h3h 5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
type: "card (4 missing: 9C 5D QD...)", type: "card (4 missing: 9C 5D QD...)",
events: "48", events: "48",
bits: "208", bits: "212",
words: 18, words: 18,
strength: "centuries", strength: "centuries",
} }
@@ -3447,20 +3451,21 @@ it("Shows details about the entered entropy", function(done) {
entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks", entropy: "ac2c3c4c5c6c7c8c tcjcqckcad2d3d4d 6d 8d9d jd kdah2h3h 5h6h7h8h9hthjhqhkh 2s3s4s5s6s7s8s9stsjsqsks",
type: "card", type: "card",
events: "45", events: "45",
bits: "195", bits: "198",
words: 18, words: 18,
strength: "centuries", strength: "centuries",
} }
); );
}); });
it("Shows details about the entered entropy", function(done) { it("Shows details about the entered entropy", function(done) {
// multiple decks does not affect the bits per event
// since the bits are hardcoded in entropy.js
testEntropyFeedback(done, testEntropyFeedback(done,
// Multiple decks of cards increases bits per event
{ {
entropy: "3d", entropy: "3d",
events: "1", events: "1",
bits: "4", bits: "5",
bitsPerEvent: "4.34", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3469,8 +3474,8 @@ it("Shows details about the entered entropy", function(done) {
{ {
entropy: "3d3d", entropy: "3d3d",
events: "2", events: "2",
bits: "9", bits: "10",
bitsPerEvent: "4.80", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3480,7 +3485,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "3d3d3d", entropy: "3d3d3d",
events: "3", events: "3",
bits: "15", bits: "15",
bitsPerEvent: "5.01", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3490,7 +3495,7 @@ it("Shows details about the entered entropy", function(done) {
entropy: "3d3d3d3d", entropy: "3d3d3d3d",
events: "4", events: "4",
bits: "20", bits: "20",
bitsPerEvent: "5.14", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3499,8 +3504,8 @@ it("Shows details about the entered entropy", function(done) {
{ {
entropy: "3d3d3d3d3d", entropy: "3d3d3d3d3d",
events: "5", events: "5",
bits: "26", bits: "25",
bitsPerEvent: "5.22", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3509,8 +3514,8 @@ it("Shows details about the entered entropy", function(done) {
{ {
entropy: "3d3d3d3d3d3d", entropy: "3d3d3d3d3d3d",
events: "6", events: "6",
bits: "31", bits: "30",
bitsPerEvent: "5.28", bitsPerEvent: "4.46",
} }
); );
}); });
@@ -3519,8 +3524,8 @@ it("Shows details about the entered entropy", function(done) {
{ {
entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d", entropy: "3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d3d",
events: "33", events: "33",
bits: "184", bits: "165",
bitsPerEvent: "5.59", bitsPerEvent: "4.46",
strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"', strength: 'less than a second - Repeats like "abcabcabc" are only slightly harder to guess than "abc"',
} }
); );
@@ -3571,10 +3576,11 @@ it('Converts very long entropy to very long mnemonics', function(done) {
// https://bip32jp.github.io/english/index.html // https://bip32jp.github.io/english/index.html
// NOTES: // NOTES:
// Is incompatible with: // Is incompatible with:
// base 6
// base 20 // base 20
it('Is compatible with bip32jp.github.io', function(done) { it('Is compatible with bip32jp.github.io', function(done) {
var entropy = "543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543210543"; var entropy = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
var expectedPhrase = "train then jungle barely whip fiber purpose puppy eagle cloud clump hospital robot brave balcony utility detect estate old green desk skill multiply virus"; var expectedPhrase = "primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary fetch primary foster";
driver.findElement(By.css('.use-entropy')) driver.findElement(By.css('.use-entropy'))
.click(); .click();
driver.findElement(By.css('.entropy')) driver.findElement(By.css('.entropy'))