Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.