Last active
February 22, 2020 21:09
-
-
Save reasonset/215ab93fe882b7eb84df48b51ec474eb 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/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