Skip to content

Commit

Permalink
Add option -D/--delimiter-special.
Browse files Browse the repository at this point in the history
  • Loading branch information
htgoebel committed Apr 29, 2019
1 parent 6a1a762 commit 03b3db5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changes
0.9.7.dev0 (yet unreleased)
---------------------------

(no changes yet)
- Added option ``--delimiter-special``. Thanks to `Hartmut Goebel
<https://crazy-compilers.com>`_.
- Added German, Italien, Latin and two Spanish wordlists. Thanks to
`Hartmut Goebel <https://crazy-compilers.com>`_.

0.9.6 (2018-12-19)
------------------
Expand Down
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Once installed, use ``--help`` to list all available options::
Insert NUM special chars into generated word.
-d DELIMITER, --delimiter DELIMITER
Separate words by DELIMITER. Empty string by default.
-D NUM, --delimiter-special NUM
Separate words by NUM special chars (none by default).
-r SOURCE, --randomsource SOURCE
Get randomness from this source. Possible values:
`realdice', `system'. Default: system
Expand Down Expand Up @@ -208,6 +210,7 @@ directory. This file could look like this::
caps = off
specials = 2
delimiter = "MYDELIMITER"
delimiter_special = 0
randomsource = "system"
wordlist = "en_securedrop"

Expand Down Expand Up @@ -412,6 +415,8 @@ People that helped spotting bugs, providing solutions, etc.:
- `Simon Fondrie-Teitler <https://github.com/simonft>`_ contributed a
machine-readable copyright file, with improvements from `@anarcat`_
- `Doug Muth <https://github.com/dmuth>`_ fixed formatting in docs.
- `Hartmut Goebel <https://crazy-compilers.com>`_ added option
``--delimiter-special`` and some wordlists.

Many thanks to all of them!

Expand Down
13 changes: 12 additions & 1 deletion diceware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def handle_options(args):
parser.add_argument(
'-d', '--delimiter', default='',
help="Separate words by DELIMITER. Empty string by default.")
parser.add_argument(
'-D', '--delimiter-special', default=0, type=int, metavar='NUM',
help="Separate words by NUM special chars (none by default).")
parser.add_argument(
'-r', '--randomsource', default='system', choices=random_sources,
metavar="SOURCE",
Expand Down Expand Up @@ -190,7 +193,15 @@ def get_passphrase(options=None):
words = [rnd.choice(list(word_list)) for x in range(options.num)]
if options.caps:
words = [x.capitalize() for x in words]
result = options.delimiter.join(words)
if options.delimiter_special:
lengths = list(range(1, options.delimiter_special + 1))
for pos in range(len(words)-1, 0, -1):
l = rnd.choice(lengths)
deli = "".join(rnd.choice(SPECIAL_CHARS) for j in range(l))
words.insert(pos, deli)
result = "".join(words)
else:
result = options.delimiter.join(words)
for _ in range(options.specials):
result = insert_special_char(result, rnd=rnd)
return result
Expand Down
1 change: 1 addition & 0 deletions diceware/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
caps=True,
specials=0,
delimiter="",
delimiter_special=0,
randomsource="system",
verbose=0,
wordlist="en_eff",
Expand Down
1 change: 1 addition & 0 deletions tests/sample_dot_diceware.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ num = 6
caps = on
specials = 0
delimiter = ""
delimiter_special = 0
randomsource = "system"
verbose = 0
wordlist = "en_securedrop"
Expand Down

0 comments on commit 03b3db5

Please sign in to comment.