class Frasier::Generator
Public Class Methods
new(word_list, number_of_words = 5)
click to toggle source
# File lib/frasier/generator.rb, line 4 def initialize(word_list, number_of_words = 5) @number_of_words = number_of_words @word_list = word_list end
Public Instance Methods
bits_of_entropy()
click to toggle source
Entropy = 2^n
# File lib/frasier/generator.rb, line 33 def bits_of_entropy Math.log(entropy, 2).round(2) end
duration_to_guess(number_of_guesses_per_second = 10000)
click to toggle source
Passphrase is probably guessed in 2^n-1
Returns the seconds it takes to guess the passphrase
# File lib/frasier/generator.rb, line 40 def duration_to_guess(number_of_guesses_per_second = 10000) entropy/2.0/number_of_guesses_per_second.to_f end
entropy()
click to toggle source
Total number of combinations possible, represent the total entropy
# File lib/frasier/generator.rb, line 28 def entropy @word_list.length ** @number_of_words end
passphrase()
click to toggle source
# File lib/frasier/generator.rb, line 21 def passphrase (0...@number_of_words).map do |i| random_word end.join(" ") end
random_word()
click to toggle source
Simulate 5 dice rolls and get the word from our list
# File lib/frasier/generator.rb, line 15 def random_word word = @word_list[[roll, roll, roll, roll, roll].join("")] return word if word random_word end
roll()
click to toggle source
A roll of the dice.
# File lib/frasier/generator.rb, line 10 def roll rand(5) + 1 end