Generate Diceware passphrases
Properly includes the wordlist in the distribution. Adds functions to load the list of words and return random ones based off the number generator. The diceware module was restructured and an inefficiency in numgen() was corrected.
This commit is contained in:
parent
f904ef2e2f
commit
ab5cfd013e
@ -28,19 +28,21 @@ class GUI:
|
|||||||
frame = tk.Frame(master, padx=50, pady=50)
|
frame = tk.Frame(master, padx=50, pady=50)
|
||||||
frame.pack()
|
frame.pack()
|
||||||
|
|
||||||
msgtxt = "Here are some random Diceware numbers for you!"
|
msgtxt = "Here is a strong random passphrase for you!"
|
||||||
msg = tk.Label(frame, pady=15, font=("Arial", 16), text=msgtxt)
|
msg = tk.Label(frame, pady=15, font=("Arial", 16), text=msgtxt)
|
||||||
msg.pack()
|
msg.pack()
|
||||||
|
|
||||||
for number in diceware.numgen(7):
|
pwgen = diceware.gen()
|
||||||
text = tk.Label(frame, font=("FreeMono", 16), text=number)
|
if pwgen.loadlist("dicekey/wordlist.asc"):
|
||||||
|
passwd = ' '.join(pwgen.wordgen(7))
|
||||||
|
text = tk.Label(frame, font=("FreeMono", 16), text=passwd)
|
||||||
text.pack()
|
text.pack()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
root = tk.Tk()
|
root = tk.Tk()
|
||||||
root.wm_title("Dicekey – Password Generator")
|
root.wm_title("Dicekey – Passphrase Generator")
|
||||||
interface = GUI(root)
|
interface = GUI(root)
|
||||||
|
|
||||||
root.mainloop()
|
root.mainloop()
|
||||||
|
@ -15,20 +15,57 @@
|
|||||||
|
|
||||||
# Built-in
|
# Built-in
|
||||||
import random
|
import random
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
# Generate Diceware numbers
|
class gen:
|
||||||
def numgen(length=1):
|
|
||||||
numlist = []
|
|
||||||
|
|
||||||
for _ in range(length):
|
wordlist = {}
|
||||||
number = ""
|
|
||||||
|
|
||||||
for _ in range(5):
|
# Generate Diceware numbers
|
||||||
PRNG = random.SystemRandom()
|
def numgen(self, length=1):
|
||||||
digit = PRNG.randint(1, 6)
|
numlist = []
|
||||||
number = number + str(digit)
|
|
||||||
|
|
||||||
numlist.append(number)
|
PRNG = random.SystemRandom()
|
||||||
|
|
||||||
return numlist
|
for _ in range(length):
|
||||||
|
number = ""
|
||||||
|
|
||||||
|
for _ in range(5):
|
||||||
|
digit = PRNG.randint(1, 6)
|
||||||
|
number = number + str(digit)
|
||||||
|
|
||||||
|
numlist.append(number)
|
||||||
|
|
||||||
|
return numlist
|
||||||
|
|
||||||
|
|
||||||
|
# Load list of numbers/words
|
||||||
|
def loadlist(self, listloc):
|
||||||
|
listfile = open(listloc, "Ur")
|
||||||
|
data = listfile.readlines()
|
||||||
|
|
||||||
|
for line in data:
|
||||||
|
if not line.find("\t") is -1:
|
||||||
|
number, word = line[:-1].split("\t", 1)
|
||||||
|
|
||||||
|
if re.match("^[1-6]{5}$", number):
|
||||||
|
if not number in self.wordlist:
|
||||||
|
self.wordlist[number] = word
|
||||||
|
|
||||||
|
# Ensure the list is complete
|
||||||
|
if len(self.wordlist) == 7776:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
self.wordlist = {}
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# Generate password
|
||||||
|
def wordgen(self, length):
|
||||||
|
words = []
|
||||||
|
|
||||||
|
for dicenum in self.numgen(length):
|
||||||
|
words.append(self.wordlist[dicenum])
|
||||||
|
|
||||||
|
return words
|
||||||
|
4
setup.py
4
setup.py
@ -17,7 +17,7 @@
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
NAME = "Dicekey"
|
NAME = "Dicekey"
|
||||||
VERSION = "1.2.0-prealpha"
|
VERSION = "2.0.0-prealpha"
|
||||||
AUTHOR = "Kris Lamoureux"
|
AUTHOR = "Kris Lamoureux"
|
||||||
AUTHOR_EMAIL = "KrisPublicEmail@gmail.com"
|
AUTHOR_EMAIL = "KrisPublicEmail@gmail.com"
|
||||||
URL = "https://github.com/Kris619/Dicekey/"
|
URL = "https://github.com/Kris619/Dicekey/"
|
||||||
@ -33,5 +33,5 @@ setup(
|
|||||||
url=URL,
|
url=URL,
|
||||||
scripts = ["dicekey/dicekey"],
|
scripts = ["dicekey/dicekey"],
|
||||||
py_modules = ["dicekey.core", "dicekey.diceware"],
|
py_modules = ["dicekey.core", "dicekey.diceware"],
|
||||||
package_data={"dicekey": ["dicekey/wordlist.asc"]}
|
data_files = [("dicekey/wordlist.asc", '')]
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user