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:
Kris Lamoureux 2016-11-07 22:49:08 -05:00
parent f904ef2e2f
commit ab5cfd013e
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925
3 changed files with 56 additions and 17 deletions

View File

@ -28,19 +28,21 @@ class GUI:
frame = tk.Frame(master, padx=50, pady=50)
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.pack()
for number in diceware.numgen(7):
text = tk.Label(frame, font=("FreeMono", 16), text=number)
pwgen = diceware.gen()
if pwgen.loadlist("dicekey/wordlist.asc"):
passwd = ' '.join(pwgen.wordgen(7))
text = tk.Label(frame, font=("FreeMono", 16), text=passwd)
text.pack()
def main():
root = tk.Tk()
root.wm_title("Dicekey Password Generator")
root.wm_title("Dicekey Passphrase Generator")
interface = GUI(root)
root.mainloop()

View File

@ -15,20 +15,57 @@
# Built-in
import random
import re
# Generate Diceware numbers
def numgen(length=1):
numlist = []
class gen:
for _ in range(length):
number = ""
wordlist = {}
for _ in range(5):
PRNG = random.SystemRandom()
digit = PRNG.randint(1, 6)
number = number + str(digit)
# Generate Diceware numbers
def numgen(self, length=1):
numlist = []
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

View File

@ -17,7 +17,7 @@
from distutils.core import setup
NAME = "Dicekey"
VERSION = "1.2.0-prealpha"
VERSION = "2.0.0-prealpha"
AUTHOR = "Kris Lamoureux"
AUTHOR_EMAIL = "KrisPublicEmail@gmail.com"
URL = "https://github.com/Kris619/Dicekey/"
@ -33,5 +33,5 @@ setup(
url=URL,
scripts = ["dicekey/dicekey"],
py_modules = ["dicekey.core", "dicekey.diceware"],
package_data={"dicekey": ["dicekey/wordlist.asc"]}
data_files = [("dicekey/wordlist.asc", '')]
)