Skip to content

Instantly share code, notes, and snippets.

@naftulikay
Created October 13, 2016 05:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naftulikay/ded4f76c11d43f2574352d241b3e6a2c to your computer and use it in GitHub Desktop.
Save naftulikay/ded4f76c11d43f2574352d241b3e6a2c to your computer and use it in GitHub Desktop.
Generate a random password with a given problem space complexity.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from math import ceil, log
from string import ascii_lowercase, ascii_uppercase, digits
# use system random
from random import SystemRandom
random = SystemRandom()
lookalikes = "1lI0O"
passphrase_chars = ''.join(filter(lambda a: a not in lookalikes,
ascii_lowercase + ascii_uppercase + digits))
def main():
problem_space = 192 # bits
min_digits = ceil(log(2**problem_space, len(passphrase_chars)))
passphrase = ''.join([random.choice(passphrase_chars) for i in
range(min_digits)])
print("{}: {}".format(min_digits, passphrase))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment