-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpassword_cracker.rb
41 lines (36 loc) · 981 Bytes
/
password_cracker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby
require 'eldritch'
require 'digest/md5'
if ARGV.size < 2
puts 'Cracks 4 lowercase letter password hashed using MD5'
puts
puts 'usage: password_cracker.rb <threads> <hash>'
puts ' threads: the number of threads to run'
puts ' hash: MD5 hash to crack'
puts
puts 'example:'
puts ' password_cracker.rb 4 31d7c3e829be03400641f80b821ef728'
puts ' prints "butts"'
exit 1
end
threads = ARGV.shift.to_i
hash = ARGV.shift
# generate all possible 4 lowercase letter passwords
passwords = ('a'..'z').to_a.repeated_permutation(4).lazy.map &:join
together do |group|
# cut the passwords into slices
passwords.each_slice(passwords.size/threads) do |slice|
async do
slice.each do |password|
if hash == Digest::MD5.hexdigest(password)
group.synchronize do
puts password
# stop the other tasks
group.interrupt
break
end
end
end
end
end
end