Skip to content

Commit

Permalink
fix: randomized_delimiter_join #150
Browse files Browse the repository at this point in the history
Only insert random delimiter between words.
  • Loading branch information
davidshen84 committed Aug 17, 2023
1 parent 7f64870 commit fea90ec
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ nosetests.xml
.vscode

# mypy
.mypy_cache
.mypy_cache

.idea/
6 changes: 6 additions & 0 deletions tests/test_xkcdpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ def test_delim(self):
delimiter=tdelim)
self.assertIsNotNone(re.match('([a-z]+(_|$))+', result))

def test_random_delimiter(self):
wordlist = xkcd_password.generate_wordlist(WORDFILE, min_length=3, max_length=3)
result = xkcd_password.generate_xkcdpassword(wordlist, numwords=3, random_delimiters=True)

self.assertEqual(11, len(result))

def test_set_case(self):
words = "this is only a test".lower().split()
words_before = set(words)
Expand Down
8 changes: 2 additions & 6 deletions xkcdpass/xkcd_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,7 @@ def randomized_delimiter_join(words, delimiters=DEFAULT_DELIMITERS):
Join the words into a password with random delimiters between each word
"""

final_passwd = ''
for word in words:
final_passwd += choose_delimiter(delimiters) + word

return final_passwd + choose_delimiter(delimiters)
return ''.join(map(lambda w: w + choose_delimiter(delimiters), words))[:-1]

def choose_delimiter(delimiters):
"""
Expand Down Expand Up @@ -496,7 +492,7 @@ def _add_arguments(self):
self.add_argument(
"-D", "--valid-delimiters",
dest="valid_delimiters", default="", metavar="VALID_DELIMITERS",
help=("A string with all valid delimiter charcters."
help=("A string with all valid delimiter characters."
" For example, '^&*' would use ^, &, or *"))
self.add_argument(
"-s", "--separator",
Expand Down

0 comments on commit fea90ec

Please sign in to comment.