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:in
`block (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:in
`block 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:in
`setup_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:in `new'
  from (irb):2
  from /usr/bin/irb:12:in `<main>'

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
-- 
Posted via http://www.ruby-forum.com/.