aboutsummaryrefslogtreecommitdiffhomepage
path: root/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'test.c')
-rw-r--r--test.c73
1 files changed, 50 insertions, 23 deletions
diff --git a/test.c b/test.c
index bb0f8bd..f2e48d5 100644
--- a/test.c
+++ b/test.c
@@ -27,7 +27,7 @@
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
- *
+ *
**********************************************************************************/
#include <stdio.h>
@@ -56,33 +56,47 @@ static void CalcPass(const char *Pwd, int Quiet)
int Len, ChkLen;
struct timeval t1, t2;
ZxcMatch_t *Info, *p;
+ double m = 0.0;
gettimeofday(&t1, 0);
e = ZxcvbnMatch(Pwd, UsrDict, &Info);
gettimeofday(&t2, 0);
-
+ for(p = Info; p; p = p->Next)
+ m += p->Entrpy;
+
Len = strlen(Pwd);
- printf("Pass %s \tLength %d\tEntropy %.3f\n", Pwd, Len, e);
+ m = e - m;
+ printf("Pass %s \tLength %d\tEntropy bits=%.3f log10=%.3f\tMulti-word extra bits=%.1f\n", Pwd, Len, e, e * 0.301029996, m);
p = Info;
ChkLen = 0;
while(p)
{
int n;
- switch(p->Type)
+ switch((int)p->Type)
{
- case BRUTE_MATCH: printf(" Type: Bruteforce"); break;
- case DICTIONARY_MATCH: printf(" Type: Dictionary"); break;
- case DICT_LEET_MATCH: printf(" Type: Dict+Leet "); break;
- case USER_MATCH: printf(" Type: User Words"); break;
- case USER_LEET_MATCH: printf(" Type: User+Leet "); break;
- case REPEATS_MATCH: printf(" Type: Repeated "); break;
- case SEQUENCE_MATCH: printf(" Type: Sequence "); break;
- case SPATIAL_MATCH: printf(" Type: Spatial "); break;
- case DATE_MATCH: printf(" Type: Date "); break;
+ case BRUTE_MATCH: printf(" Type: Bruteforce "); break;
+ case DICTIONARY_MATCH: printf(" Type: Dictionary "); break;
+ case DICT_LEET_MATCH: printf(" Type: Dict+Leet "); break;
+ case USER_MATCH: printf(" Type: User Words "); break;
+ case USER_LEET_MATCH: printf(" Type: User+Leet "); break;
+ case REPEATS_MATCH: printf(" Type: Repeated "); break;
+ case SEQUENCE_MATCH: printf(" Type: Sequence "); break;
+ case SPATIAL_MATCH: printf(" Type: Spatial "); break;
+ case DATE_MATCH: printf(" Type: Date "); break;
+ case BRUTE_MATCH+MULTIPLE_MATCH: printf(" Type: Bruteforce(Rep)"); break;
+ case DICTIONARY_MATCH+MULTIPLE_MATCH: printf(" Type: Dictionary(Rep)"); break;
+ case DICT_LEET_MATCH+MULTIPLE_MATCH: printf(" Type: Dict+Leet(Rep) "); break;
+ case USER_MATCH+MULTIPLE_MATCH: printf(" Type: User Words(Rep)"); break;
+ case USER_LEET_MATCH+MULTIPLE_MATCH: printf(" Type: User+Leet(Rep) "); break;
+ case REPEATS_MATCH+MULTIPLE_MATCH: printf(" Type: Repeated(Rep) "); break;
+ case SEQUENCE_MATCH+MULTIPLE_MATCH: printf(" Type: Sequence(Rep) "); break;
+ case SPATIAL_MATCH+MULTIPLE_MATCH: printf(" Type: Spatial(Rep) "); break;
+ case DATE_MATCH+MULTIPLE_MATCH: printf(" Type: Date(Rep) "); break;
+
default: printf(" Type: Unknown%d ", p->Type); break;
}
ChkLen += p->Length;
- printf(" Length %d Entropy %6.3f ", p->Length, p->Entrpy);
+ printf(" Length %d Entropy %6.3f (%.2f) ", p->Length, p->Entrpy, p->Entrpy * 0.301029996);
for(n = 0; n < p->Length; ++n, ++Pwd)
printf("%c", *Pwd);
printf("\n");
@@ -137,7 +151,7 @@ int DoChecks(char *file)
/* Skip leading whitespace */
while(*Pwd && (*Pwd <= ' '))
++Pwd;
-
+
/* Make password null termnated */
s = Pwd;
t = strchr(s, '\t');
@@ -150,7 +164,7 @@ int DoChecks(char *file)
break;
}
*t++ = 0;
-
+
/* Skip whitespace before entropy value */
while(*t && (*t <= ' '))
++t;
@@ -160,7 +174,7 @@ int DoChecks(char *file)
r = 1;
break;
}
-
+
Ent = atof(t);
if ((Ent < 0.0) || (Ent > 1000.0))
{
@@ -187,9 +201,10 @@ int DoChecks(char *file)
int main(int argc, char **argv)
{
- int i, Quiet, Checks;
+ int i, Quiet, Checks, White;
Quiet = 0;
Checks = 0;
+ White = 0;
if (!ZxcvbnInit("zxcvbn.dict"))
{
printf("Failed to open dictionary file\n");
@@ -197,22 +212,29 @@ int main(int argc, char **argv)
}
if ((argc > 1) && (argv[1][0] == '-'))
{
- Checks = !strcmp(argv[1], "-t");
- Quiet = !strcmp(argv[1], "-q");
- if ((Checks + Quiet) == 0)
+ if (!strcmp(argv[1], "-qs") || !strcmp(argv[1], "-sq"))
+ Quiet = White = 1;
+ if (!strcmp(argv[1], "-t"))
+ Checks = 1;
+ if (!strcmp(argv[1], "-q"))
+ Quiet = 1;
+ if (!strcmp(argv[1], "-s"))
+ White = 1;
+ if ((Checks + Quiet + White) == 0)
{
char *s = strrchr(argv[0], '/');
if (s == NULL)
s = argv[0];
else
++s;
- printf( "Usage: %s [ -q ] [ pwd1 pwd2 ... ]\n"
+ printf( "Usage: %s [ -q | -qs ] [ pwd1 pwd2 ... ]\n"
" Output entropy of given passwords. If no passwords on command line read\n"
" them from stdin.\n"
" -q option stops password analysis details from being output.\n"
+ " -s Ignore anything from space on a line when reading from stdin.\n"
" %s -t file\n"
" Read the file and check for correct results.\n", s, s);
-
+
return 1;
}
}
@@ -241,6 +263,11 @@ int main(int argc, char **argv)
Line[i] = 0;
break;
}
+ if (White && (Line[i] == ' '))
+ {
+ Line[i] = 0;
+ break;
+ }
}
if (Line[0])
CalcPass(Line, Quiet);