Skip to content

Instantly share code, notes, and snippets.

@luckman212
Last active January 25, 2023 15:01
Show Gist options
  • Save luckman212/5547ebc03e87bbe7895e1d74ea2ab681 to your computer and use it in GitHub Desktop.
Save luckman212/5547ebc03e87bbe7895e1d74ea2ab681 to your computer and use it in GitHub Desktop.
small wrapper around diceware (https://pypi.org/project/diceware) to implement multiple passphrase generation
#!/usr/bin/env python3
"""
generates multiple random passphrases in one go
https://github.com/ulif/diceware/issues/53
requires diceware: pip install diceware
"""
import os
import sys
import random
from itertools import repeat
import diceware as dw
PASSWORDS = []
ITERATIONS = 1
DEFAULT_ARGS = [ '-c', '-n2' ]
args = sys.argv[1:]
if not args:
args = DEFAULT_ARGS
if '-i' in args:
s = args.index('-i')
ITERATIONS = int(args[s+1])
del args[s:s+2]
options = dw.handle_options(args)
dw.configure(options.verbose)
try:
for _ in repeat(None, ITERATIONS):
PASSWORDS.append(dw.get_passphrase(options))
except (OSError, IOError) as infile_error:
if getattr(infile_error, 'errno', 0) == ENOENT:
print("The file '%s' does not exist." % infile_error.filename, file=sys.stderr)
raise SystemExit(1)
else:
raise
print(*PASSWORDS, sep = "\n")
@luckman212
Copy link
Author

luckman212 commented Jan 6, 2023

Setup

  • install diceware pip install diceware
  • save script somewhere in your $PATH as e.g. pwgen-dw.py
  • make it executable chmod +x pwgen-dw.py
  • use the new -i N parameter to specify # of iterations
  • optional: change DEFAULT_ARGS to suit your liking

Usage

$ pwgen-dw.py -i 5 -n 3
SpongyWashroomEmu
BuddhismMantisParmesan
ArrayImpedingSkeletal
ChubbyChapsHuddle
EtchingSwarmGatherer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment