Class: PassphraseEntropy

Inherits:
Object
  • Object
show all
Defined in:
lib/passphrase_entropy.rb,
lib/passphrase_entropy/version.rb

Overview

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.

Constant Summary collapse

VERSION =
"0.1.1"

Instance Method Summary collapse

Constructor Details

#initialize(dictionary = default_dictionary) ⇒ PassphraseEntropy

Instantiate a new PasswordEntropy calculator. dictionary should be a String containing a list of words; this is /usr/share/dict/words by default, which should be good for English systems.



13
14
15
# File 'lib/passphrase_entropy.rb', line 13

def initialize(dictionary=default_dictionary)
  @dictionary = dictionary
end

Instance Method Details

#entropy(s) ⇒ Object

Estimate the entropy of s (in bytes)



19
20
21
# File 'lib/passphrase_entropy.rb', line 19

def entropy(s)
  zlen(s) - baseline
end

#inspect(*args) ⇒ Object



23
24
25
# File 'lib/passphrase_entropy.rb', line 23

def inspect(*args)
  to_s
end