Module: Zxcvbn::Math Private
- Included in:
- Guesses
- Defined in:
- lib/zxcvbn/math.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Mathematical utilities used by the guess estimation logic.
Instance Method Summary collapse
-
#average_degree_for_graph(graph_name) ⇒ Float
private
Returns the precomputed average key-adjacency degree for a keyboard graph.
-
#nCk(n, k) ⇒ Integer
private
Computes the binomial coefficient C(n, k) (“n choose k”).
-
#starting_positions_for_graph(graph_name) ⇒ Integer
private
Returns the number of starting positions (keys) in a keyboard graph.
Instance Method Details
#average_degree_for_graph(graph_name) ⇒ Float
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the precomputed average key-adjacency degree for a keyboard graph.
33 34 35 |
# File 'lib/zxcvbn/math.rb', line 33 def average_degree_for_graph(graph_name) data.graph_stats[graph_name][:average_degree] end |
#nCk(n, k) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Computes the binomial coefficient C(n, k) (“n choose k”).
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/zxcvbn/math.rb', line 12 def nCk(n, k) return 0 if k > n return 1 if k.zero? # Use symmetry property: C(n,k) = C(n, n-k) # Choose smaller k to minimize iterations k = n - k if k > n - k r = 1 (1..k).each do |d| r *= n r /= d n -= 1 end r end |
#starting_positions_for_graph(graph_name) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the number of starting positions (keys) in a keyboard graph.
41 42 43 |
# File 'lib/zxcvbn/math.rb', line 41 def starting_positions_for_graph(graph_name) data.graph_stats[graph_name][:starting_positions] end |