Skip to content

Instantly share code, notes, and snippets.

@lucasmartins
Forked from lpar/pwgen.rb
Created June 12, 2012 15:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasmartins/2918200 to your computer and use it in GitHub Desktop.
Save lucasmartins/2918200 to your computer and use it in GitHub Desktop.
Simple generation of readable tokens using Ruby
#!/usr/bin/env ruby
# encoding: UTF-8
# Simple readable password generation in Ruby.
#
# Generate reasonably secure random passwords of any chosen length,
# designed to be somewhat easy for humans to read and remember.
# Each password has a capitalized letter and a digit.
#
# Example:
#
# pwgen = PasswordGenerator.new
# for i in 0..10
# puts pwgen.generate(8)
# end
#
# pwgen.generate_laywersafe(8)
#
class ReadableToken
# These are some koremutake syllables, plus the most common 2 and 3 letter
# syllables taken from the most common 5,000 words in Brazillian Portuguese (pt_br), minus a few
# syllables removed so that combinations cannot generate common rude
# words in Brazillian Portuguese (pt_br).
SYLLABLES = %w(ba be bi bo bu da de di do du fa fe fi fo fu ga ge gi
go gu ho ja je ji jo ju ka ke ko ku la le li lo lu ma me mi mo mu na ne
ni no nu pa pe pi po pu ra re ri ro ru sa se si so su ta te ti to tu va
ve vi vo vu bra bri bro bru dre dri dro dru fra fri fro fru gra gri
gro gru pra pre pri pro pru nte ao es ndo ca co ter com cal nho ver ter ser
ora rda za ze zi zo zu xa xe xi xo xu)
CURSES = %w(fod fud ralho puta bucet vagin pau pica rola saco escrot babaca bagos
baitola besta bicha bixa biscate bisca boceta boiola bolagato boquete bolcat bosseta
boceta bosta bostana bronha buceta bund burr busseta cachorra cadela caga cagao cagad
cagona canalha caralho cassete cacete checheca chereca chifrud chota chochota chupad
cocaina coco corn corrupt cretin cu curalho cuzao cuzuada cuzudo debil demonio doid egua
escrot estupid fedid fedor fedorenta feio feia felaçao fod fornica fudendo fudecao
fudid gay gonorreia gonorrea gosment homo sexo sexual homosexual homossexual idiot imbecil
iscrot ladra ladrao ladro lepros lesbic macac machona machorra manguaca masturb
melec merda mija mijad mijo mocrea mocreia moleca moleque mondrog nojent otar paspalh
pau peid pemba penis pentelho perereca pica picao pilantra piranha piru porra prostibul
prostitut punhet pus pustula puta puts putaria puxa-saco puxasaco rabao rabud rachadinh
ramelao retadard retardad ridicul rola rolinha rolao rosca rapariga safad sapatao sifilis
siririca tarad testud narigud cabecuda tezuda tezao trocha trouxa troucha trolha troxa vaca
vagabund vagina vead viad xerereca cherereca xexeca xota chota xoxot chochot xana chana
xaninha chaninha)
def self::generate(length)
srand
recursion_countdown=20
result = self.generate_token(length)
while CURSES.include?(result) && recursion_countdown>0
if recursion_countdown<=0
raise "Token generator too dirty, prepare the lawyers!"
end
sleep 0.001
result = self.generate_token(length)
recursion_countdown-=1
end
return result
end
private
def self::generate_token(length)
result = ''
while result.length < length
syl = SYLLABLES[rand(SYLLABLES.length)]
result += syl
end
result = result[0,length]
# Stick in a digit
dpos = rand(length)
wrapped_numbers="-#{rand(9).to_s}#{rand(9).to_s}-"
result.insert dpos,wrapped_numbers
if result[0]=='-'
result=result[1..result.size-1]
end
if result[result.size]=='-'
result=result[0..result.size-2]
end
# Make a letter capitalized
#cpos = rand(length)
#result[cpos,1] = result[cpos,1].swapcase
return result.upcase
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment