Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
diceware-debian
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drebs
diceware-debian
Commits
46328804
Commit
46328804
authored
10 years ago
by
ulif
Browse files
Options
Downloads
Patches
Plain Diff
First sketch of main password generator.
parent
d5bfefe3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
diceware/diceware.py
+20
-0
20 additions, 0 deletions
diceware/diceware.py
tests/test_diceware.py
+9
-1
9 additions, 1 deletion
tests/test_diceware.py
with
29 additions
and
1 deletion
diceware/diceware.py
+
20
−
0
View file @
46328804
import
os
import
re
from
random
import
SystemRandom
#: The directory in which wordlists are stored
SRC_DIR
=
os
.
path
.
dirname
(
__file__
)
...
...
@@ -7,6 +9,8 @@ SRC_DIR = os.path.dirname(__file__)
#: A regular expression matching ASCII chars
RE_ASCII_CHARS
=
re
.
compile
(
'
^[a-zA-Z]{2}$
'
)
#: Special chars inserted on demand
SPECIAL_CHARS
=
"
~!#$%^&*()-=+[]\{}:;
\"
'
<>?/0123456789
"
def
get_wordlist
(
path
):
"""
Parse file at `path` and build a word list of it.
...
...
@@ -43,5 +47,21 @@ def get_wordlist_path(lang):
return
os
.
path
.
abspath
(
os
.
path
.
join
(
SRC_DIR
,
basename
.
lower
()))
def
get_passphrase
(
wordnum
=
6
,
specials
=
True
,
separator
=
''
,
lang
=
'
en
'
,
capitalized
=
True
):
"""
Get a diceware passphrase.
"""
word_list
=
get_wordlist
(
get_wordlist_path
(
lang
))
rnd
=
SystemRandom
()
words
=
[
rnd
.
choice
(
word_list
)
for
x
in
range
(
wordnum
)]
if
capitalized
:
words
=
[
x
.
capitalize
()
for
x
in
words
]
result
=
separator
.
join
(
words
)
result
=
list
(
result
)
result
[
rnd
.
choice
(
range
(
len
(
result
)))]
=
rnd
.
choice
(
SPECIAL_CHARS
)
result
=
''
.
join
(
result
)
return
result
def
main
():
pass
This diff is collapsed.
Click to expand it.
tests/test_diceware.py
+
9
−
1
View file @
46328804
import
os
import
pytest
from
diceware.diceware
import
SRC_DIR
,
get_wordlist
,
get_wordlist_path
from
diceware.diceware
import
(
SRC_DIR
,
get_wordlist
,
get_wordlist_path
,
get_passphrase
,
)
class
Test_GetWordList
(
object
):
...
...
@@ -57,3 +59,9 @@ class TestDicewareModule(object):
assert
os
.
path
.
basename
(
get_wordlist_path
(
'
de
'
))
==
'
wordlist_de.asc
'
assert
os
.
path
.
basename
(
get_wordlist_path
(
'
De
'
))
==
'
wordlist_de.asc
'
assert
os
.
path
.
basename
(
get_wordlist_path
(
'
DE
'
))
==
'
wordlist_de.asc
'
def
test_get_passphrase
(
self
):
# we can get passphrases
r1
=
get_passphrase
()
r2
=
get_passphrase
()
assert
r1
!=
r2
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment