Last active
August 29, 2015 13:56
-
-
Save Ninjex/9020611 to your computer and use it in GitHub Desktop.
MD5 Lookup Table Generator
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
#!/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