Skip to content

Instantly share code, notes, and snippets.

@jfreeze
Created February 2, 2012 15:46
Show Gist options
  • Save jfreeze/1724068 to your computer and use it in GitHub Desktop.
Save jfreeze/1724068 to your computer and use it in GitHub Desktop.
Passphrase Generator
class Array
def qrand
self[rand(self.size)]
end
end
module Generate
def generate
@data.qrand
end
end
class RandName
extend Generate
PATH = "/usr/share/dict/propernames"
@data ||= File.read(PATH).split(/\s/m)
end
class RandConnective
extend Generate
PATH = "/usr/share/dict/connectives"
@data ||= File.read(PATH).split(/\s/m)
end
class RandWord
extend Generate
PATH = "/usr/share/dict/web2"
@data ||= File.read(PATH).split(/\s/m)
end
class RandNumber
def self.generate
rand(10**rand(5)).to_s
end
end
class RandSep
extend Generate
@data = ['.', '-', '=', ' ', '']
end
objects = [RandName, RandConnective, RandWord, RandNumber]
10.times do
times = rand(3) + 2
pass_phrase = ""
times.times do |time|
pass_phrase << objects.qrand.generate
pass_phrase << RandSep.generate unless time == times-1
end
puts pass_phrase
end
Running “passphrase-generator.rb”…
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
hymnologic=Cygnus=Mario
allArchie1446
mybeforealmemar
antialbumin.that Jakob
men=formaldehydesulphoxylic=5.3
stum.palch=bewitchery
for=Kenn89-Eva
aldehydase1903.for 79
0whomsoeverhas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment