Skip to content

Instantly share code, notes, and snippets.

@Harrisoon
Created November 28, 2018 16:32
Show Gist options
  • Save Harrisoon/409c52dc72f8e65f6507d0d9cea50bb0 to your computer and use it in GitHub Desktop.
Save Harrisoon/409c52dc72f8e65f6507d0d9cea50bb0 to your computer and use it in GitHub Desktop.
pw
#!/usr/bin/env python3
import secrets as s
"""
This program generates a password of length n.
Programma also generates a code name of length n.
Requires the dictionary.txt and the nouns and adjective files to run
"""
class Generator:
def __init__(self, number_of_words = 2, pw_number_of_words=5):
self.number_of_words = number_of_words
self.pw_number_of_words = pw_number_of_words
def word_Gen(self):
"""
Generate a random code name of n number of words, seperated by 1 * whitespace
Opens local .txt files
@param number_of_words: Desired length of password
"""
password = ""
counter= 0
while counter < self.number_of_words:
if counter == 0:
stn = "nouns"
elif counter == 1:
stn = "adjectives"
route = s.randbelow(4)
text_file = open(stn+"/"+str(route+1)+"syllable"+stn+".txt").readlines()
word = text_file[s.randbelow(len(text_file))]
password+=word[:-1]+" "
counter+=1
return password
def code_Name_Creator(self):
# feeling-busy-this-03??
x = 1
"""
Prints code-name to the screen.
"""
while x <= 100:
print(str(x) +"\t"+ self.word_Gen())
x+=1
def Word_Password(self):
"""
Generate a password of n number of words, seperated by 1 * whitespace, random whether the
characters are uppercase.
@param number_of_words: Desired length of password
"""
pswd = ""
text_file = open("Dictionary/dictionary.txt").readlines()
text_length = len(text_file)
counter = 0
while counter < self.pw_number_of_words:
wrd = text_file[s.randbelow(text_length)][:-1]
r = s.randbelow(4)+1
if 4 % r:
wrd = wrd.upper()
if r == 1:
space = "-"
grammer = "!"
elif r == 2:
space = "_"
grammer = "?"
elif r == 3:
space = " "
grammer = "/"
else:
space = "~"
grammer = "|"
pswd += (wrd+space)
counter+=1
for x in range(0, 2):
pswd += str(s.randbelow(8)+1)
for x in range(0, 2):
pswd += grammer
return pswd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment