domenica 9 agosto 2009

Building a pronounceable password generator in Ruby

Heya guys! Today I tried to build a pronounceable password generator. To keep it simple, I started from a simple concatenation of words - in my case, italian words. This is really easy, but you'll see that results will be very good.

I took a list of italian words from this site: Italian dictionary and affix file for ispell. It's a good choice because ispell dictionaries are prepared to be declined; concatenating two words without suffixes will give good results for pronounceability.

Before proceeding, however, I needed to narrow the words list:

I removed the ispell affix definitions, to get words like "abaco" instead of "abaco/G":
cat italian.words | sed 's/\/[A-Z]*//g' > parole.txt
I removed all words containing capital letters, like "Yamaha", "Windows", and "Acicastello":
cat parole.txt | sed '/[a-z]*[A-Z][a-z]*/d' > paroleNoCapital.txt
Finally, I sedded out some cuss words - not writing them here, for the sake of decency! :)

I was then ready to write the following ruby script:

def genera_pass_da(parole, n = 2)
how_many_words = parole.size
word = ''
1.upto(n) do
word += parole[rand(how_many_words)].chomp
end
word
end

file = File.open("parole.txt")
parole = file.lines.to_a.select { |word| word.size < 7 }
1.upto(10) do
puts genera_pass_da parole
end
Even if it's far from being polished and optimized, launching this gives a good set of pronounceable passwords. They're all lowercase and without numbers - so probably not the best choice for your remote banking account - but still ok for other uses. Here's a shot:

metalelf0@eagleone$ ruby rapg.rb
uditovoi
vammimidi
gechitua
dareisisma
ecoivi
ancabatto
unotacca
fangopupe
apesella
bemasire
Someday I'll improve it by adding numbers, some capital letters, customizing choices and so on - but many friends are yelling me that it's sunday and I need to go out, so... see ya soon!

Nessun commento:

Posta un commento