Created
May 10, 2015 21:46
-
-
Save oro350/889317b8ac2dfcb42352 to your computer and use it in GitHub Desktop.
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/env ruby | |
DEFAULT_REPEAT = '10' | |
DEFAULT_CHARS = 16 | |
TEMPLATE_NUMBER = '0123456789' | |
TEMPLATE_SHORT = TEMPLATE_NUMBER + 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | |
TEMPLATE_LONG = TEMPLATE_SHORT + '!@#$%^&*()_+|~`\={}[];:<>,./?"\'' | |
$template = TEMPLATE_SHORT | |
$chars = DEFAULT_CHARS | |
require 'optparse' | |
Version = '0.0.1' | |
ARGV.options do |opt| | |
opt.banner = "Usage: #{File.basename($0)} [repeats]" | |
opt.on('-l', '--long') {|o| $template = TEMPLATE_LONG } | |
opt.on('-n', '--number') {|o| $template = TEMPLATE_NUMBER } | |
opt.on('-c', '--chars count') {|o| $chars = o.to_i(0) } | |
opt.parse! | |
end | |
def genpass(str, num) | |
num.times.inject("") { |r, n| r << str[rand(str.size)].chr } | |
end | |
(ARGV.pop||DEFAULT_REPEAT).to_i(0).times { puts genpass($template, $chars) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment