Created
October 28, 2016 02:42
-
-
Save pvgdevelop/93876f6fce461b3b02b3739b5ce12b13 to your computer and use it in GitHub Desktop.
Brute force md5 password crack. Using recursion
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' | |
def combinator(arr, comb_arr = arr, len) | |
return if len == 0 | |
if len == 1 | |
return comb_arr | |
else | |
tmp_arr = [] | |
arr.each do |ch| | |
comb_arr.each do |comb| | |
tmp_arr << comb + ch | |
end | |
end | |
combinator(arr, tmp_arr, len - 1) | |
end | |
end | |
def pwd_brute_force(md5_str, len) | |
alphabet = ('a'..'z').to_a | |
pwd_combos = combinator(alphabet, len) | |
pwd_combos.each do |pwd| | |
return pwd if Digest::SHA1.hexdigest(pwd) == md5_str | |
end | |
'Not found' | |
end | |
md5_str = Digest::SHA1.hexdigest("hey") | |
puts pwd_brute_force(md5_str, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment