]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Missing cards are detected
authorIan Coleman <coleman.ian@gmail.com>
Thu, 17 Nov 2016 00:59:15 +0000 (11:59 +1100)
committerIan Coleman <coleman.ian@gmail.com>
Thu, 17 Nov 2016 00:59:15 +0000 (11:59 +1100)
src/js/index.js
tests.js

index 6a81601cd5c738b5abc8f4504d5cce59575e4e84..f4163ee08e55b1b71173ae429485175806d13fd7 100644 (file)
             if (uniqueCards.length == 52) {
                 cardDetail.unshift("full deck");
             }
+            // Detect missing cards
+            var values = "A23456789TJQK";
+            var suits = "CDHS";
+            var missingCards = [];
+            for (var i=0; i<suits.length; i++) {
+                for (var j=0; j<values.length; j++) {
+                    var card = values[j] + suits[i];
+                    if (!(card in dupeTracker)) {
+                        missingCards.push(card);
+                    }
+                }
+            }
+            // Display missing cards if six or less, ie clearly going for full deck
+            if (missingCards.length > 0 && missingCards.length <= 6) {
+                var msg = missingCards.length + " missing: " + missingCards.slice(0,3).join(" ");
+                if (missingCards.length > 3) {
+                    msg += "...";
+                }
+                cardDetail.push(msg);
+            }
             // Add card details to typeStr
             if (cardDetail.length > 0) {
                 typeStr += " (" + cardDetail.join(", ") + ")";
index a0de5febd8ee3ceb56165b11226d8b10898cfceb..13f2c76d4271e1fc28321609b8d3e022560fffc9 100644 (file)
--- a/tests.js
+++ b/tests.js
@@ -2650,7 +2650,7 @@ page.open(url, function(status) {
         },
         {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d",
-            type: "card (2 duplicates: 3d 4d)",
+            type: "card (2 duplicates: 3d 4d, 1 missing: KS)",
             events: 53,
             bits: 232,
             words: 27,
@@ -2658,7 +2658,7 @@ page.open(url, function(status) {
         },
         {
             entropy: "ac2c3c4c5c6c7c8c9ctcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqs3d4d5d6d",
-            type: "card (4 duplicates: 3d 4d 5d...)",
+            type: "card (4 duplicates: 3d 4d 5d..., 1 missing: KS)",
             events: 53,
             bits: 243,
             words: 27,
@@ -2690,6 +2690,40 @@ page.open(url, function(status) {
             words: 0,
             strength: "extremely weak",
         },
+        // Missing cards are detected
+        {
+            entropy: "ac2c3c4c5c6c7c8c  tcjcqckcad2d3d4d5d6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
+            type: "card (1 missing: 9C)",
+            events: 51,
+            bits: 226,
+            words: 27,
+            strength: "extremely strong",
+        },
+        {
+            entropy: "ac2c3c4c5c6c7c8c  tcjcqckcad2d3d4d  6d7d8d9dtdjdqdkdah2h3h4h5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
+            type: "card (2 missing: 9C 5D)",
+            events: 50,
+            bits: 225,
+            words: 24,
+            strength: "extremely strong",
+        },
+        {
+            entropy: "ac2c3c4c5c6c7c8c  tcjcqckcad2d3d4d  6d7d8d9dtdjd  kdah2h3h  5h6h7h8h9hthjhqhkhas2s3s4s5s6s7s8s9stsjsqsks",
+            type: "card (4 missing: 9C 5D QD...)",
+            events: 48,
+            bits: 221,
+            words: 24,
+            strength: "extremely strong",
+        },
+        // More than six missing cards does not show message
+        {
+            entropy: "ac2c3c4c5c6c7c8c  tcjcqckcad2d3d4d  6d  8d9d  jd  kdah2h3h  5h6h7h8h9hthjhqhkh  2s3s4s5s6s7s8s9stsjsqsks",
+            type: "card",
+            events: 45,
+            bits: 214,
+            words: 24,
+            strength: "extremely strong",
+        },
     ];
     // use entropy
     page.evaluate(function() {