Any RC4 decryption lib for ruby 1.9.2?

680 views Asked by At

i found one lib which is here
https://github.com/juggler/ruby-rc4/blob/master/lib/rc4.rb

But its not working for ruby 1.9.x
it throws an error undefined method ^' for "\x1A":String__

is there any work around in ruby 1.9.x?

after googling i came to know that "In Ruby 1.9 string[index] returns character not code of the character (like it was in 1.8)." (https://rails.lighthouseapp.com/projects/8994/tickets/3144-undefined-method-for-string-ror-234)

Thanks in advance

2

There are 2 answers

3
Michael Papile On

https://github.com/dotemacs/ruby-rc4/tree/master/lib This guy has forked it, and added some tests. The original is not maintained it looks like. This library is extremely simple and to fix that you just have to use the ord method on String.

 s = "foo"
 s[0].ord

So clone that guys git, fix it, and send him a pull request, it is the open source way :) if he does not respond then keep your fork and people will then use that.

EDIT

change line 27 to:

  0.upto(text.length-1) {|i| text[i] = [text[i].ord ^round].pack('c')}
2
Matti Virkkunen On

If that (one operation) is the only problem, couldn't you just modify the library a bit?