Random Seriousness with Python and Password Generation

My last post was a little light hearted look at playing with randomness , but randomness can be a much more useful tool in many areas of computing. My favourite being Monte Carlo Simulations, but I’ll save that for another article. Today we’re generating passwords and using Python on Linux to help us do so.

Thinking up unique, high entropy passwords that are hard to guess and easy to remember is a difficult thing for people to do. From what I’ve seen, the 2 things tend to be inversely related, if only FqcA632yK(G^gdM6Z}Pk1xAZFYLVhE}Wy would stick in your mind after a couple of repetitions.

Here I’m introducing a couple of scripts that I’ve used occasionally over the last few years to give myself and other people some fairly sane unique passwords.

You can get them here on Github:

Random Words Pass Phrase

This one’s similar to an idea depicted in the XKCD Passwords Comic , generating a ‘pass phrase’ from randomly selected common words. These can be fairly easily remembered or spoken over the phone.

$ rand_words 
mahoganies stamped goof 1@\
$ rand_words 
franchise Slavonic Copeland 0],
$ rand_words 
relishes odorous velour 58[
$ rand_words 
urination cajoled escapist 945
$ rand_words 
fulfilment slowdown infrared .0#
$ rand_words 
Rocco submerging stilted 2&9

It uses the Linux dictionary in /usr/share/dict/words for its source of words. To set it up as a command in your path so that you can use anywhere, you might want to symlink it with something like:

$ sudo ln -s /path/to/your/directory/rand_words \ 

There’s a few optional arguments to the script to fine tune your password generation.

They come in the form:

$ rand_words \

Play around and see what suits you best.

$ rand_words 4 10 4
Joy rage dopy Sims 8@174127*[
$ rand_words 4 0 6
toots plinth shuts cheep 
$ rand_words 6 5 3
leg Tex hex met out Fr |00~6

Windows Users

If you’re running Windows or an OS without an easily available dictionary to use, there are many freely available options on the web e.g.

Compact High Entropy Passwords

rand_words does the job, but occasionally you’ll be faced with software or services enforcing daft password requirements / restrictions like “Your password must be less than 10 characters”. For these situations rand_chars helps you generate a bunch of random printable characters that you can select your password from:

$ rand_chars 10 50

The first argument is the number of lines to generate and the second is the length of those lines. The script defaults to 10 lines of 80 characters long.

You may find it useful to symlink rand_chars, as we did before with rand_words.


I think Randall Munroe’s quote says it best:

“Through 20 years of effort, we’ve successfully trained everyone to use passwords that are hard for humans to remember, but easy for computers to guess.”

Let’s stop using (and re-using) crappy passwords and start trying to do simple security better. It’s a Wild West out there on the Web and the Internet, make sure you don’t become easy prey to the highwaymen.

Tags: Linux, Security

blog comments powered by Disqus


@MTerzza Twitter Icon

+MikeTerzza Google Plus Icon

Atom | RSS RSS Icon

Recent Posts:

Monitoring the progress of dd

RTL SDR Frequency Drift Offset

Random Seriousness with Python and Password Generation

Random Fun and the Busy Linux Geek

Ampersands & on the command line