Skip to content

Instantly share code, notes, and snippets.

@hatkidchan
Created January 27, 2023 08:12
Show Gist options
  • Save hatkidchan/f1ed4f15072195593635d3fd4ddd727c to your computer and use it in GitHub Desktop.
Save hatkidchan/f1ed4f15072195593635d3fd4ddd727c to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from random import choice, shuffle, randint
from re import findall
from os.path import expanduser
from sys import argv
with open(expanduser("/usr/share/keepassxc/wordlists/eff_large.wordlist"), "r") as f:
words = list(map(str.strip, f.readlines()))
password_mask = list(argv[1] if len(argv) > 1 else "WWWWWWWWWWWWWWWWDDDS")
#password_mask = list("WWWWWWWWDDS")
while True:
shuffle(password_mask)
password_mask_str = str.join("", password_mask)
parts = findall(r"W+|D+|S+", password_mask_str)
n_words = sum(1 if part[0] == "W" else 0 for part in parts)
shortest_word = min(len(part) for part in parts if part[0] == "W")
longest_number = max(len(part) for part in parts if part[0] == "D")
if (n_words <= 3
and shortest_word >= 6
and longest_number <= 2
and parts[0][0] not in ("SD")):
break
password = []
for part in parts:
if part[0] == "W":
word = choice(list(filter(lambda w: len(w) == len(part), words)))
if randint(0, 100) <= 30:
word = word.upper()
password.append(word)
elif part[0] == "S":
password.append(choice("!#%-._+="))
elif part[0] == "D":
password.append(("%%0%dd" % len(part)) % randint(0, 10 ** len(part[0])))
print(str.join("", password))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment