Created
August 3, 2017 22:43
-
-
Save Freaky/4cb7ce8c107c3da2e4a8210356e8da25 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'digest/sha1' | |
# search a file of "<sha1><crlf>" | |
def sha1_binsearch(io, target, linesize = 42, hashsize=40) | |
low, high = 0, (io.size / linesize) - 1 | |
while low <= high | |
mid = (low + high) / 2 | |
io.pos = mid * linesize | |
midval = io.read(hashsize) | |
if midval < target | |
low = mid + 1 | |
elsif midval > target | |
high = mid - 1 | |
else | |
return true | |
end | |
end | |
return false | |
end | |
db = File.new 'pwned-passwords-1.0.txt' | |
loop do | |
print "Password: " | |
pass = $stdin.gets.chomp | |
exit if pass.empty? | |
a = Time.new.to_f | |
hash = Digest::SHA1.hexdigest(pass).upcase | |
puts "Found: %s in %.2f ms" % [sha1_binsearch(db, hash), (Time.new.to_f - a) * 1000] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment