Skip to content

Commit

Permalink
reversed word dictionary matching
Browse files Browse the repository at this point in the history
  • Loading branch information
lowe committed Sep 14, 2015
1 parent ceaac0c commit 45b17a6
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/matching.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ matching =
matches = []
matchers = [
@dictionary_match
@reverse_dictionary_match
@l33t_match
@spatial_match
@repeat_match
Expand Down Expand Up @@ -130,6 +131,20 @@ matching =
matched_word: word
rank: rank
dictionary_name: dictionary_name
reversed: false
@sorted matches

reverse_dictionary_match: (password, _ranked_dictionaries = RANKED_DICTIONARIES) ->
reversed_password = password.split('').reverse().join('')
matches = @dictionary_match reversed_password, _ranked_dictionaries
for match in matches
match.token = match.token.split('').reverse().join('') # reverse back
match.reversed = true
# map coordinates back to original string
[match.i, match.j] = [
password.length - 1 - match.j
password.length - 1 - match.i
]
@sorted matches

set_user_input_dictionary: (ordered_list) ->
Expand Down
5 changes: 3 additions & 2 deletions src/scoring.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ scoring =
dictionary_entropy: (match) ->
match.base_entropy = @lg match.rank # keep these as properties for display purposes
match.uppercase_entropy = @extra_uppercase_entropy match
match.l33t_entropy = @extra_l33t_entropy match
match.base_entropy + match.uppercase_entropy + match.l33t_entropy
match.reversed_entropy = match.reversed and 1 or 0
match.l33t_entropy = @extra_l33t_entropy(match)
match.base_entropy + match.uppercase_entropy + match.l33t_entropy + match.reversed_entropy

START_UPPER: /^[A-Z][^A-Z]+$/
END_UPPER: /^[^A-Z]+[A-Z]$/
Expand Down
18 changes: 18 additions & 0 deletions test/test-matching.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ test 'dictionary matching', (t) ->
t.end()


test 'reverse dictionary matching', (t) ->
test_dicts =
d1:
123: 1
321: 2
456: 3
654: 4
password = '0123456789'
matches = matching.reverse_dictionary_match password, test_dicts
msg = 'matches against reversed words'
check_matches msg, t, matches, 'dictionary', ['123', '456'], [[1, 3], [4, 6]],
matched_word: ['321', '654']
reversed: [true, true]
dictionary_name: ['d1', 'd1']
rank: [2, 4]
t.end()


test 'l33t matching', (t) ->
test_table =
a: ['4', '@']
Expand Down
7 changes: 7 additions & 0 deletions test/test-scoring.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,13 @@ test 'dictionary_entropy', (t) ->
msg = "extra entropy is added for capitalization"
t.equal scoring.dictionary_entropy(match), lg(32) + scoring.extra_uppercase_entropy(match), msg

match =
token: 'aaa'
rank: 32
reversed: true
msg = "1 bit of extra entropy is added for reversed words"
t.equal scoring.dictionary_entropy(match), lg(32) + 1, msg

match =
token: 'aaa@@@'
rank: 32
Expand Down

0 comments on commit 45b17a6

Please sign in to comment.