Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

XKCD Password Generator

Introduction

Apparently, this question has been asked here and it unfortunately closed. I thought it was a good idea to try again with it, but done right.

XKCD looks at the how we are trained to use "hard to remember passwords", thinking it's secure, but instead, would take a computer 3 days to crack. On the flip side, remembering 4-5 words brings Kuan's Password Intropy up, and is easy to remember. Crazy how that works, huh?

Challenge

The job today is to create 5 passwords using words. 4 words per password and a minimum of 4 letters per word, but no maximum. Kuan's Password Intropy will need to be calculated for every password, but a forced minimum will not be set.

What is Kuan's Password Intropy?

Kuan's Password Intropy is a measurement of how unpredictable a password is, according to Kuan. There is a simple calculation: E = log2(R) * L. E being Kuan's Password Intropy, R being range of available characters and L for password length.

Range of available characters is self explanatory. It's the range of characters that a password can have, in this case is Upper and lower case. Since there is 26 characters in the alphabet, 26 x 2 = 52 characters in the whole range of the password.

Password Length is also self explanatory. It's the total length of the password after creation.

Constraints

  • No input.
  • A word cannot reappear in the same password.
  • No symbols or numbers allowed in a password.
  • 4 words per password, but a forced minimum of 4 letters per word.
  • No spaces between words.
  • You cannot generate the same password over and over again.
  • Each word has to be capitalized in a password.
  • Output has to be human-readable, must be spaced out. Must also include Kuan's Password Intropy of the password with it using Kuan's Password Intropy equation above.
  • Dictionary. You must use this, download it as a text file and integrate accordingly. This will be the list from which you grab words from. Your code should assume its available.
  • This is , shortest bytes win.

Output

TriedScarProgressPopulation 153.9
TryingPastOnesPutting 119.7
YearnGasesDeerGiven 108.3
DoubtFeetSomebodyCreature 142.5
LiquidSureDreamCatch 114.0

Answer*

Cancel
5
  • \$\begingroup\$ Python lists don't have shuffle method, and you can save two bytes in Python 2 by removing parenthesis around exec (exec is a keyword in Python 2). \$\endgroup\$ Commented May 25, 2017 at 20:35
  • \$\begingroup\$ @xfix Yeah it should be shuffle(f);. \$\endgroup\$ Commented May 25, 2017 at 20:41
  • \$\begingroup\$ Whoops, fixing that asap \$\endgroup\$ Commented May 25, 2017 at 21:17
  • 4
    \$\begingroup\$ You could use my trick of noting that the rounding at 5.7 is fine to 1 decimal place so long as floating point errors are not introduced and save five bytes with 57*len(x)/10.. Save another byte by removing the parentheses making the print take a tuple. Here is a cut-down version: TIO \$\endgroup\$ Commented May 25, 2017 at 21:27
  • \$\begingroup\$ Use sample(f,4) instead of shuffle. Also f can just be open('dict.txt').read().split('\n'), open('dict.txt').readlines(), or just open('dict.txt') (I know it's not golfed but still). \$\endgroup\$ Commented May 25, 2017 at 22:32