Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimslawson/6042976 to your computer and use it in GitHub Desktop.
Save kimslawson/6042976 to your computer and use it in GitHub Desktop.
Acrostic function for generating passphrases, contributed to https://github.com/redacted/XKCD-password-generator
def find_acrostic(acrostic, wordlist):
"""
Constrain choice of words to those beginning with the letters of the given word (acrostic)
"""
"""
# slower but more elegant. "pythonic"
while 1:
words = " ".join(rng().sample(wordlist, n_words))
if acrostic.lower() == "".join(item[0] for item in words.split()).lower():
return words
break
"""
# faster but less elegant. practical.
words = ""
for letter in acrostic:
while 1:
word = rng().choice(wordlist)
if word[0] == letter:
words += word + " "
break
return words
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment