Skip to content

Instantly share code, notes, and snippets.

@reasonset reasonset/mkpwd.rb
Last active Feb 22, 2020

Embed
What would you like to do?
#!/usr/bin/ruby
# -*- mode: ruby; coding: utf-8 -*-
pwlength = ARGV.shift&.to_i || 64
pwlength = 64 if pwlength < 1
converter_symbols = ARGV.shift&.each_char
converter = converter_symbols ? ("a" .. "z").to_a + ("A" .. "Z").to_a + ("0" .. "9").to_a + converter_symbols : ('!' .. '~').to_a
convloops = 255 / converter.length
convlength = converter.length * convloops
File.open("/dev/urandom", "r") do |f|
pwlength.times do |i|
c = f.readbyte
redo if c >= convlength
print(converter[c % converter.length])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.