On Thu, May 17, 2012 at 6:38 PM, roob noob <lists / ruby-forum.com> wrote:
> =A0def contains_dictionary_word?(password)
> =A0entropy_bits =3D 0
> =A0passed_dictionary_test =3D true
> =A0File.open("#{RELATIVEPATH}/data/dictionary") do |dictionary|
> =A0 =A0while line =3D dictionary.gets
> =A0 =A0 =A0passed_dictionary_test =3D false and break if
> password.include?(line.chop)
> =A0 =A0end
> =A0 =A0entropy_bits =3D 6 if passed_dictionary_test and password.length >=
 4
> =A0 =A0end
> =A0 =A0return entropy_bits
> =A0end

Two notes:

1. By common ruby convention, methods ending with a ? return a
boolean, not an int

2. This does not do what you think it does:

  passed_dictionary_test =3D false and break if password.include?(line.chop=
)

it parses as

(passed_dictionary_test =3D false) and (break if password.include?(line.cho=
p))

then (passed_dictionary_test =3D false) is an expression, which returns
its rhs, which is false, so the bit after the "and" is never
evaluated. The following code is illustrative - guess what it does,
then run it and see:

x =3D 0
passed =3D true
while x < 10
  passed =3D false and break if x =3D=3D 5
  puts "x =3D #{x}, passed =3D #{passed}"
  x +=3D 1
end


This form of your original code works:

    if password.include?(line.chop)
        passed_dictionary_test =3D false
        break
    end

martin