Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Last active August 29, 2015 13:56
Show Gist options
  • Save Ninjex/9020611 to your computer and use it in GitHub Desktop.
Save Ninjex/9020611 to your computer and use it in GitHub Desktop.
MD5 Lookup Table Generator
#!/usr/bin/ruby
require 'digest/md5' # Hashing strings to MD5
if ARGV[0] != '-i' || ARGV[2] != '-o' || ARGV[3].nil?
puts "Syntax Error!"
puts "Usage: ruby lookup.rb -i <input file> -o <output file>"
else
input_file = ARGV[1]
if File.exist?(input_file)
output_file = ARGV[3]
text = File.open(input_file).read
text.gsub!(/\r\n?/, "\n")
text.each_line do |line|
line.strip!
hash = Digest::MD5.hexdigest(line)
write = "#{hash}:#{line}" # Place hash first in case 'line' contains a semicolon
File.open(output_file, 'a+') {|f| f.write(write+"\r\n")}
end
else
puts "The input file: #{input_file} is invalid, check your syntax and try again!"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment