Code golf challenge: XKCD 936 passwords

random832 at fastmail.us random832 at fastmail.us
Wed Oct 9 16:22:31 EDT 2013


On Tue, Oct 8, 2013, at 18:27, Rob Day wrote:
> On 08/10/13 07:17, Chris Angelico wrote:
> > Who's up for some fun? Implement an XKCD-936-compliant password
> > generator in Python 3, in less code than this:
> >
> > print(*__import__("random").sample(open("/usr/share/dict/words").read().split("\n"),4))
> >
> >
> print("imploring epsilon decamp graveyard's")
> # Chosen by fair random sampling, guaranteed to be random

Of course, the choice of dictionary makes all the difference in the
world.

print('kayo wide sitz keen')
# Chosen by fair random sampling among SOWPODS words of four or fewer
letters.
# This is a set of 6870 words, XKCD Std. #936 requires a set of at least
2048.
# This password's 50.98 bits of entropy exceed the standard's
recommendations by 6.98.

This can be further improved to the standard's recommended entropy level
(but not strictly the same method) by selecting only the first one from
this set, and selecting the remaining four words from the set of 1416
words of 3 letters or less, for 44.14 bits of entropy:
print('axis ar cha tam')

Or, keeping with the spirit of the standard, mix the set of 1416 words 3
letters or less with 632 randomly selected words from the four-letter
set:
print('pal alp govs deb')



More information about the Python-list mailing list