Trouble using blowfish

Hello Group,

ruby version: ruby 1.9.1p243

I get the following error when I try creating a new instance of
blowfish.

irb(main):001:0> require ‘crypt/blowfish’
=> true

irb(main):002:0> blowfish = Crypt::Blowfish.new(“key”)
TypeError: can’t convert String into Integer
from
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:47:in
|' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:47:inblock (2 levels) in setup_blowfish’
from
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:46:in
times' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:46:inblock in setup_blowfish’
from
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:44:in
upto' from /usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:44:insetup_blowfish’
from
/usr/local/ruby/lib/ruby/gems/1.9.1/gems/crypt-1.1.4/crypt/blowfish.rb:27:in
initialize' from (irb):2:innew’
from (irb):2
from /usr/bin/irb:12:in `’

The problem seems to be on the code presented below:

46: 4.times {
47: data = ((data << 8) | @key[keypos]) % ULONG
48: keypos = (keypos.next) % @key.length
49: }

data = 0

@key = “key”

keypos = 0

ULONG = 0x100000000

On line 47, data <<8 is an integer and @key[keypos]) % ULONG is a
string.
This is probably the causing ‘can’t convert String into Integer’ error.

I have very limited programing knowledge and I do not know the best way
to fix this code.
Any help will be greatly appreciated.

Regards,
Ashita

Ashita H. wrote:

irb(main):002:0> blowfish = Crypt::Blowfish.new(“key”)
from
`initialize’

to fix this code.
Any help will be greatly appreciated.

Regards,
Ashita

The gem you are using apparently has not been updated to work with Ruby
1.9.

You can try changing @key[keypos] to @key[keypos].ord

However, there may be other incompatibilities in the gem.

-Justin

Hello Justin,

Thank you for your advise. That did the trick.

Regards,
Ashita

Justin C. wrote:

Ashita H. wrote:

irb(main):002:0> blowfish = Crypt::Blowfish.new(“key”)
from
`initialize’

to fix this code.
Any help will be greatly appreciated.

Regards,
Ashita

The gem you are using apparently has not been updated to work with Ruby
1.9.

You can try changing @key[keypos] to @key[keypos].ord

However, there may be other incompatibilities in the gem.

-Justin