require 'luksbf' # args: device cachefile keyslot_id [distributed id] [distributed total] # for 3 processes, launch with '0 3' / '1 3' / '2 3' dev = ARGV.shift || '/dev/sda1' log = ARGV.shift || 'luksbf.log' keyslot = ARGV.shift.to_i # default to 0 stripe = ARGV.shift.to_i stripemax = ARGV.shift.to_i # list of prefixes def gen_pfx yield '' %w[pfx1 pfx2].each { |w| yield w } end # list of suffixes, sends 'suffix' and 'Suffix' def gen_sfx yield '' %w[sfx1 sfx2].each { |w| yield w ; yield w.capitalize } end def gen_keys gen_pfx { |p1| gen_sfx { |p2| mutate(p1+p2) { |w| yield w ; yield '!'+w } } } end # toto => 'toto', 't0to', 'tot0', 't0t0' def mutate(w) co = w.count('o') ci = w.count('i') ce = w.count('e') max = co+ci+ce wm = nil swap = lambda { |i| o = -1 if i < co (i+1).times { o = w.index('o', o+1) } wm[o] = ?0 elsif i < co+ci i -= co (i+1).times { o = w.index('i', o+1) } wm[o] = ?1 else i -= co+ci (i+1).times { o = w.index('e', o+1) } wm[o] = ?3 end } (1 << max).times { |mask| wm = w.dup max.times { |mi| swap[mi] if mask[mi] == 1 } yield wm } end #mutate('lololilol') { |w| p w } ; exit bf = LuksBF.new(dev) done = {} File.read(log).each { |l| done[l[/(.*) /, 1]] = l[/ (.*)$/, 1].chomp } if File.exist? log max = 0 gen_keys { max += 1 } cntr = 0 gen_keys { |k| cntr += 1 next if stripemax > 0 and cntr % stripemax != stripe print "\r#{cntr}/#{max}".ljust(20) $stdout.flush if not dk = done[k] dk = bf.derive(k, keyslot) File.open(log, 'a') { |fd| fd.puts "#{k} #{dk}" } done[k] = dk end if bf.test_derived(dk, keyslot) # must run as root on the original dev puts '', k.inspect # bingo end } puts