Skip to content

Instantly share code, notes, and snippets.

@handicraftsman
Last active January 15, 2017 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save handicraftsman/6fd6e9353d1524caad1c7a3536b57a83 to your computer and use it in GitHub Desktop.
Save handicraftsman/6fd6e9353d1524caad1c7a3536b57a83 to your computer and use it in GitHub Desktop.
Generates strong random passwords
require "date"
dt = DateTime.now
base = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
blen = base.length
passlen = ARGV[0]
if passlen == "-"
passlen = gets
end
if passlen == nil then
fail "Passlen arg is not provided!"
end
if passlen[/\D+\n/]
fail "Given data is not number!"
end
passlen = passlen.to_i
pass = ""
tfa = %w[%Y %C %y %m %d %e %j %H %k %I %l %M %S %L %:::z %u %w %G %g %V %U %W %s %Q %3N %6N %9N %12N].shuffle
passlen.times do |i|
f = ""
tfa = tfa.shuffle
tfa.each do |o|
f << o
end
seed =
dt.
strftime(f).
delete(": ").
to_i
rndbts = Random.new.bytes(128).bytes.sum ** 4096
s = Random.new_seed + seed + i*i + rndbts
s = s**128
rnd = Random.new
pos = rnd.rand(0..(blen-1))
pass << base[pos]
sleep 0.01
end
(passlen.floor / 12).times do
pass[(0..(passlen-1)).to_a.sample] = "_"
pass[(0..(passlen-1)).to_a.sample] = "."
end
puts "#{pass}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment