Commit 0590504d authored by Benjamin REED's avatar Benjamin REED

added dictionary

parent 373857fb
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -14,6 +14,8 @@ from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC ...@@ -14,6 +14,8 @@ from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
import rsa import rsa
from rsa import RsaKey from rsa import RsaKey
DICTIONARY_PATH = "French.dic"
DEFAULT_DATABASE_PATH = "db.txt" DEFAULT_DATABASE_PATH = "db.txt"
USAGES = { USAGES = {
"new": "new":
...@@ -333,11 +335,25 @@ class State: ...@@ -333,11 +335,25 @@ class State:
""" """
Generate a password given a 'set' object of characters to choose from. Generate a password given a 'set' object of characters to choose from.
""" """
def generate_password(length, charset): def generate_password(length, charset, words: bool = False):
s = [] if words:
for i in range(0, length): s = []
s.append(random.choice(list(charset))) dic = open(DICTIONARY_PATH)
return ''.join(s) lines = dic.read().split('\n') # 2 MEGABYTES by the way
for line in lines:
word = line.split('/')[0]
if len(word) >= length: continue
if len(s) + len(word) >= length:
dic.close()
return ''.join(s) + generate_password(length - len(s), charset, False)
s.extend(list(word))
dic.close()
print("Catastrophic error generating password.")
else:
s = []
for i in range(0, length):
s.append(random.choice(list(charset)))
return ''.join(s)
def handle_args(db: str, password: str): def handle_args(db: str, password: str):
state = State(db, password) state = State(db, password)
...@@ -627,18 +643,28 @@ def main(): ...@@ -627,18 +643,28 @@ def main():
continue continue
chars = set() chars = set()
words = False
if charset == "all": if charset == "all":
chars = LOWERCASE_ALPHABET | UPPERCASE_ALPHABET | NUMBERS | SPECIAL chars = LOWERCASE_ALPHABET | UPPERCASE_ALPHABET | NUMBERS | SPECIAL
else: else:
s = charset.split("-") s = charset.split("-")
for c in list(s[0]): for c in list(s[0]):
chars |= CHARSET_MAP[c] if c == 'w' or c == 'm': # words/mots
words = True
chars |= LOWERCASE_ALPHABET | UPPERCASE_ALPHABET | NUMBERS | SPECIAL
elif c not in CHARSET_MAP:
print(f"Unrecognized charset option '{c}', expected 'l', 'u', 'n', 's', or 'w'")
else:
chars |= CHARSET_MAP[c]
if len(s) > 1: if len(s) > 1:
for c in s[1]: # list of chars to exclude for c in s[1]: # list of chars to exclude
chars ^= set(c) chars ^= set(c)
if chars == set():
print("Error: unrecognizable charset provided")
continue
password = generate_password(length, chars) password = generate_password(length, chars, words)
print(password) print(password)
state.add_password(label, password.encode(), mode, key) state.add_password(label, password.encode(), mode, key)
elif command == "list" or command == "ls": elif command == "list" or command == "ls":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment