# Trouble using blowfish

**URL:** <https://www.ruby-forum.com/t/trouble-using-blowfish/183281>\
**Category:** Ruby\
**Created:** [February 11, 2010, 4:49am UTC](https://www.ruby-forum.com/t/trouble-using-blowfish/183281 "2010-02-11T04:49:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@ashita](https://www.ruby-forum.com/u/ashita)\
**Post date:** [February 11, 2010, 4:49am UTC](https://www.ruby-forum.com/t/trouble-using-blowfish/183281/1 "2010-02-11T04:49:08Z")

</div>

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 `’

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

---

<div class="post-metadata">

**Author:** ![ashita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@ashita](https://www.ruby-forum.com/u/ashita)\
**Post date:** [February 11, 2010, 5:05am UTC](https://www.ruby-forum.com/t/trouble-using-blowfish/183281/2 "2010-02-11T05:05:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ashita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/2bfe46/32.png) [@ashita](https://www.ruby-forum.com/u/ashita)\
**Post date:** [February 11, 2010, 5:11am UTC](https://www.ruby-forum.com/t/trouble-using-blowfish/183281/3 "2010-02-11T05:11:54Z")

</div>

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
