Module: Altpass
- Defined in:
- lib/altpass.rb,
lib/altpass/version.rb
Constant Summary collapse
- DEFAULT_LENGTH =
8- DEFAULT_OPTIONS =
{:length => DEFAULT_LENGTH, :memorizable => true}
- LN =
character sets divided by touch typing hands
'12345'.split('')
- RN =
Right ”
'67890' .split('')
- LL =
Left-hand Lowercase letters
('qwert'+'asdfg'+'zxcvb').split('')
- RL =
Right ” ”
('yuiop'+'hjkl'+'nm').split('')
- LU =
Left-hand Uppercase letters
LL.collect {|c| c.capitalize}
- RU =
Right ” ”
RL.collect {|c| c.capitalize}
- AMBIGUOUS =
'1lI0O' + # visually ambiguous '6b'
- VERSION =
'0.2.1'
Class Method Summary collapse
-
.generate(options = {}) ⇒ Object
return a password.
-
.permutations(options = {}) ⇒ Object
return the number of permutations, and additionally print out details when options contains v’s.
Class Method Details
.generate(options = {}) ⇒ Object
return a password
28 29 30 31 32 33 34 |
# File 'lib/altpass.rb', line 28 def self.generate(={}) = self.() password = '' iterations = [:length]/DEFAULT_LENGTH + 1 iterations.times { password += self._generate() } password.slice(0...[:length]) end |
.permutations(options = {}) ⇒ Object
return the number of permutations, and additionally print out details when options contains v’s
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/altpass.rb', line 38 def self.permutations(={}) = self.() p = 1 pattern = [:length].even? ? @pattern_even : @pattern_odd plen = pattern.length samples = [] (0...[:length]).each { |i| samples[i] = ([:memorizable] ? pattern[i%plen][0] : pattern[i%plen].flatten).reject{|c| AMBIGUOUS.include?(c)} p *= samples[i].length # take the product of all sample sizes to get the total number of permutations } if [:permutations] =~ /^v{3,}\Z/ puts 'sample sets:' samples.each {|s| puts s.inspect } end puts "#{samples.collect {|s| s.length}.join(' * ')} permutations" if [:permutations] =~ /^v{2,}\Z/ p end |