This repository has been archived by the owner. It is now read-only.
Estimate the entropy of a passphrase.
Switch branches/tags
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Estimate the entropy of a passphrase. This is calculated as the number of bytes required to encode the passphrase on top of a Deflate stream of a preset dictionary.

Inspired by xkcd 936.


require "passphrase_entropy"

pe =
# or customise the dictionary:
pe ="/usr/share/dict/words"))

pe.entropy("password") # => 6
pe.entropy("correct horse battery staple") # => 24
pe.entropy("Tr0ub4dor&3") # => 21

You can decide on your acceptable level of complexity.


It's a bit slow: the dictionary must be deflated every time. This could be ameliorated by saving the state, but that would require a modified zlib library. (It's easy to do with a pure Ruby zlib library, but Ruby is so much slower in this case that the overall gain in speed is almost zero.)

Tested using the web2 dictionary installed in Ubuntu Linux by:

apt-get install dictionaries-common miscfiles

Results will vary depending on the dictionary used.