-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrack.rb
executable file
·115 lines (88 loc) · 2.37 KB
/
crack.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
load 'word.rb'
class Crack
attr_accessor :passphrase, :password_list, :found, :start_time
def initialize(passphrase = nil)
# words in this order
self.passphrase = passphrase || ['s3ven', 'eight', 'nine']
end
def generate_password_list_file
fill_password_list
File.open("passwords-#{ self.passphrase.join }.txt", 'w') do |file|
self.password_list.each do |password|
file.puts(password)
end
end
nil
end
def run
fill_password_list
start self.password_list
end
def run_from_file(file_name)
password_list = []
File.open(file_name) { |f| password_list = f.to_a.map(&:strip) }
start password_list
end
private
def start(password_list)
self.found = false
self.start_time = Time.now
attempt_all password_list
end
def fill_password_list
self.password_list = cartesian_product(word_options).map(&:join)
end
def word_options
self.passphrase.map { |world| Word.new(world).explode }
end
def cartesian_product(array)
array.inject(&:product).map(&:flatten)
end
def attempt_all(phrases)
phrases.each_with_index do |phrase, index|
return if self.found
attempt(phrase, index + 1)
end
puts "\nNot found :(\n"
end
def attempt(phrase, count)
update_progress(phrase, count) if count % 600 == 0
system("./litecoin-cli", "walletpassphrase", phrase, "1", err: File::NULL)
case $?.exitstatus
when 0
put_alert " CRACKED! "
puts "#{phrase}"
put_alert " CRACKED! "
self.found = true
return
when 127
puts "litecoin-cli not found. Are you missing a symlink?"
end
end
def elapsed_seconds
Time.now - self.start_time
end
def update_progress(phrase, count)
attempt = "#{count.to_s.rjust(10)}"
passphrase = "#{phrase.ljust(30)}"
rate = "#{(count / elapsed_seconds).round(1)} /s"
elapsed = "#{elapsed_seconds}"
print "#{duration} - #{attempt} - #{passphrase} - #{rate}"
print "\r"
end
def put_alert(text)
pads = 20
puts text.ljust(pads + text.length, '~').rjust(2 * pads + text.length, '~')
end
def duration
total_seconds = elapsed_seconds
h = total_seconds / 3600
total_seconds -= h * 3600
m = total_seconds / 60
total_seconds -= m * 60
s = total_seconds
[h, m, s].map do |part|
part.round.to_s.rjust(2, '0')
end.join ':'
end
end