Created
September 10, 2014 01:51
-
-
Save lolptdr/a5669a2e94e5d1ce3931 to your computer and use it in GitHub Desktop.
Why you shouldn't use SHA1 to store your passwords!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest/sha1' | |
class SHA1Breaker | |
@@chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ".split("") | |
@@nums = "1234567890".split("") | |
@@lower = "abcdefghijklmnopqrstuvwxyz".split("") | |
def self.breaker(hash) | |
self.guesser(hash, @@chars) | |
end | |
def self.num_breaker(hash) | |
self.guesser(hash, @@nums) | |
end | |
def self.lower_breaker(hash) | |
self.guesser(hash, @@lower) | |
end | |
def self.guesser(hash, chars) | |
start_time = Time.now | |
guess_hash = "" | |
count = 0 | |
until guess_hash == hash do | |
guess = "" | |
guess_hash = "" | |
guess_count = count | |
guess = self.build_guess(guess_count, chars) | |
guess_hash = Digest::SHA1.hexdigest(guess) | |
count += 1 | |
end | |
end_time = Time.now | |
puts (end_time - start_time) | |
guess | |
end | |
def self.build_guess(count, chars) | |
return "1" if count == 0 | |
guess = "" | |
while count > 0 | |
guess += chars[count % chars.length] | |
count /= chars.length | |
end | |
guess | |
end | |
end | |
def get_hash(string) | |
Digest::SHA1.hexdigest(string.to_s) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment