Skip to content

Instantly share code, notes, and snippets.

@reasonset
Last active February 22, 2020 21:09
Show Gist options
  • Save reasonset/215ab93fe882b7eb84df48b51ec474eb to your computer and use it in GitHub Desktop.
Save reasonset/215ab93fe882b7eb84df48b51ec474eb to your computer and use it in GitHub Desktop.
#!/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