@@ -106,50 +106,6 @@ test 'display time', (t) ->
106106 t .equal scoring .display_time (seconds), display, msg
107107 t .end ()
108108
109- test ' extra uppercase entropy' , (t ) ->
110- for [word, extra_entropy] in [
111- [ ' ' , 0 ]
112- [ ' a' , 0 ]
113- [ ' A' , 1 ]
114- [ ' abcdef' , 0 ]
115- [ ' Abcdef' , 1 ]
116- [ ' abcdeF' , 1 ]
117- [ ' ABCDEF' , 1 ]
118- [ ' aBcdef' , lg (nCk (6 ,1 )) ]
119- [ ' aBcDef' , lg (nCk (6 ,1 ) + nCk (6 ,2 )) ]
120- [ ' ABCDEf' , lg (nCk (6 ,1 )) ]
121- [ ' aBCDEf' , lg (nCk (6 ,1 ) + nCk (6 ,2 )) ]
122- [ ' ABCdef' , lg (nCk (6 ,1 ) + nCk (6 ,2 ) + nCk (6 ,3 )) ]
123- ]
124- msg = " extra uppercase entropy of #{ word} is #{ extra_entropy} "
125- t .equal scoring .extra_uppercase_entropy (token : word), extra_entropy, msg
126- t .end ()
127-
128- test ' extra l33t entropy' , (t ) ->
129- match = l33t : false
130- t .equal scoring .extra_l33t_entropy (match), 0 , " 0 extra entropy for non-l33t matches"
131- for [word, extra_entropy, sub] in [
132- [ ' ' , 0 , {} ]
133- [ ' a' , 0 , {} ]
134- [ ' 4' , 1 , {' 4' : ' a' } ]
135- [ ' 4pple' , 1 , {' 4' : ' a' } ]
136- [ ' abcet' , 0 , {} ]
137- [ ' 4bcet' , 1 , {' 4' : ' a' } ]
138- [ ' a8cet' , 1 , {' 8' : ' b' } ]
139- [ ' abce+' , 1 , {' +' : ' t' } ]
140- [ ' 48cet' , 2 , {' 4' : ' a' , ' 8' : ' b' } ]
141- [ ' a4a4aa' , lg (nCk (6 , 2 ) + nCk (6 , 1 )), {' 4' : ' a' } ]
142- [ ' 4a4a44' , lg (nCk (6 , 2 ) + nCk (6 , 1 )), {' 4' : ' a' } ]
143- [ ' a44att+' , lg (nCk (4 , 2 ) + nCk (4 , 1 )) + lg (nCk (3 , 1 )), {' 4' : ' a' , ' +' : ' t' } ]
144- ]
145- match =
146- token : word
147- sub : sub
148- match .l33t = not matching .empty (sub)
149- msg = " extra l33t entropy of #{ word} is #{ extra_entropy} "
150- t .equal scoring .extra_l33t_entropy (match), extra_entropy, msg
151- t .end ()
152-
153109test ' minimum entropy search' , (t ) ->
154110 m = (i , j , entropy ) ->
155111 i : i
@@ -309,3 +265,85 @@ test 'date entropy', (t) ->
309265 msg += " extra entropy is added for separators and a 4-digit year."
310266 t .equal scoring .date_entropy (match), lg (12 * 31 * scoring .MIN_YEAR_SPACE ) + 2 + 1 , msg
311267 t .end ()
268+
269+ test ' dictionary_entropy' , (t ) ->
270+ match =
271+ token : ' aaaaa'
272+ rank : 32
273+ msg = " base entropy is the lg of the rank"
274+ t .equal scoring .dictionary_entropy (match), lg (32 ), msg
275+
276+ match =
277+ token : ' AAAaaa'
278+ rank : 32
279+ msg = " extra entropy is added for capitalization"
280+ t .equal scoring .dictionary_entropy (match), lg (32 ) + scoring .extra_uppercase_entropy (match), msg
281+
282+ match =
283+ token : ' aaa@@@'
284+ rank : 32
285+ l33t : true
286+ sub : {' @' : ' a' }
287+ msg = " extra entropy is added for common l33t substitutions"
288+ t .equal scoring .dictionary_entropy (match), lg (32 ) + scoring .extra_l33t_entropy (match), msg
289+
290+ match =
291+ token : ' AaA@@@'
292+ rank : 32
293+ l33t : true
294+ sub : {' @' : ' a' }
295+ msg = " extra entropy is added for both capitalization and common l33t substitutions"
296+ expected = lg (32 ) + scoring .extra_l33t_entropy (match) + scoring .extra_uppercase_entropy (match)
297+ t .equal scoring .dictionary_entropy (match), expected, msg
298+ t .end ()
299+
300+ test ' extra uppercase entropy' , (t ) ->
301+ for [word, extra_entropy] in [
302+ [ ' ' , 0 ]
303+ [ ' a' , 0 ]
304+ [ ' A' , 1 ]
305+ [ ' abcdef' , 0 ]
306+ [ ' Abcdef' , 1 ]
307+ [ ' abcdeF' , 1 ]
308+ [ ' ABCDEF' , 1 ]
309+ [ ' aBcdef' , lg (nCk (6 ,1 )) ]
310+ [ ' aBcDef' , lg (nCk (6 ,1 ) + nCk (6 ,2 )) ]
311+ [ ' ABCDEf' , lg (nCk (6 ,1 )) ]
312+ [ ' aBCDEf' , lg (nCk (6 ,1 ) + nCk (6 ,2 )) ]
313+ [ ' ABCdef' , lg (nCk (6 ,1 ) + nCk (6 ,2 ) + nCk (6 ,3 )) ]
314+ ]
315+ msg = " extra uppercase entropy of #{ word} is #{ extra_entropy} "
316+ t .equal scoring .extra_uppercase_entropy (token : word), extra_entropy, msg
317+ t .end ()
318+
319+ test ' extra l33t entropy' , (t ) ->
320+ match = l33t : false
321+ t .equal scoring .extra_l33t_entropy (match), 0 , " 0 extra entropy for non-l33t matches"
322+ for [word, extra_entropy, sub] in [
323+ [ ' ' , 0 , {} ]
324+ [ ' a' , 0 , {} ]
325+ [ ' 4' , 1 , {' 4' : ' a' } ]
326+ [ ' 4pple' , 1 , {' 4' : ' a' } ]
327+ [ ' abcet' , 0 , {} ]
328+ [ ' 4bcet' , 1 , {' 4' : ' a' } ]
329+ [ ' a8cet' , 1 , {' 8' : ' b' } ]
330+ [ ' abce+' , 1 , {' +' : ' t' } ]
331+ [ ' 48cet' , 2 , {' 4' : ' a' , ' 8' : ' b' } ]
332+ [ ' a4a4aa' , lg (nCk (6 , 2 ) + nCk (6 , 1 )), {' 4' : ' a' } ]
333+ [ ' 4a4a44' , lg (nCk (6 , 2 ) + nCk (6 , 1 )), {' 4' : ' a' } ]
334+ [ ' a44att+' , lg (nCk (4 , 2 ) + nCk (4 , 1 )) + lg (nCk (3 , 1 )), {' 4' : ' a' , ' +' : ' t' } ]
335+ ]
336+ match =
337+ token : word
338+ sub : sub
339+ l33t : not matching .empty (sub)
340+ msg = " extra l33t entropy of #{ word} is #{ extra_entropy} "
341+ t .equal scoring .extra_l33t_entropy (match), extra_entropy, msg
342+ match =
343+ token : ' Aa44aA'
344+ l33t : true
345+ sub : {' 4' : ' a' }
346+ extra_entropy = lg (nCk (6 , 2 ) + nCk (6 , 1 ))
347+ msg = " capitalization doesn't affect extra l33t entropy calc"
348+ t .equal scoring .extra_l33t_entropy (match), extra_entropy, msg
349+ t .end ()
0 commit comments