This repository has been archived by the owner on Apr 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b32768
commit 420ab69
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
PassphraseEntropy | ||
================= | ||
|
||
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](http://xkcd.com/936/). | ||
|
||
Usage | ||
----- | ||
|
||
require "passphrase_entropy" | ||
|
||
pe = PassphraseEntropy.new | ||
# or customise the dictionary: | ||
pe = PassphraseEntropy.new(File.read("/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. | ||
|
||
Notes | ||
----- | ||
|
||
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.)) |