Guest User

Untitled

a guest
Oct 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.69 KB | None | 0 0
  1. class Cracker
  2.   attr_accessor :current
  3.  
  4.   OPTS = [('a'..'z'),('A'..'Z'),('0'..'9')].map{|n| n.to_a }.flatten
  5.  
  6.   def initialize(pass)
  7.     @current = OPTS.first
  8.     crack while @current != pass
  9.     puts "Password is #{@current}"
  10.   end
  11.  
  12.   def crack
  13.     current_array = @current.split(//)
  14.     if current_array.all? {|o| o == OPTS.last}
  15.       current_array = [OPTS.first]*(current_array.length+1)      
  16.     else
  17.       poped = []
  18.       poped << current_array.pop while current_array.last == OPTS.last
  19.       last = current_array.pop
  20.       current_array.push OPTS[OPTS.index(last)+1]
  21.       current_array += ([OPTS.first]*poped.length)
  22.     end
  23.     @current = current_array.join
  24.   end
  25. end
Add Comment
Please, Sign In to add comment