News for hackers. Stuff that matters.
Re:Show HN: WordPass – password generator giving over 90 bit... by abecedarius on Sunday May 25, 2014 @01:09AM (#7795517)
Here is what I happen to have sitting around. (I'm not recommending it; there are much more secure ones. But it's short, and uses a crypto-random generator.)

    import math
    from random import SystemRandom

    cryptogen = SystemRandom()

    alphabet = open('/path/to/a/custom/wordlist').read().splitlines()
    assert len(set(alphabet)) == len(alphabet)

    def gen_token(length):
        return ','.join(cryptogen.sample(alphabet, length))

    nbits = 80
    length = int(math.ceil(nbits * math.log(2, len(alphabet))))
    print gen_token(length)

There are no comments on this comment yet.