0

我在这里找到了一个库
https://github.com/juggler/ruby-rc4/blob/master/lib/rc4.rb

但它不适用于 ruby​​ 1.9.x
它会抛出一个错误 undefined method ^' for "\x1A":String__

ruby 1.9.x 有什么解决方法吗?

谷歌搜索后,我知道“在 Ruby 1.9 中,字符串 [index] 返回字符而不是字符的代码(就像在 1.8 中一样)。” (https://rails.lighthouseapp.com/projects/8994/tickets/3144-undefined-method-for-string-ror-234)

提前致谢

4

2 回答 2

1

https://github.com/dotemacs/ruby-rc4/tree/master/lib 这家伙已经fork了它,并添加了一些测试。原来的样子没有维护。这个库非常简单,要解决这个问题,您只需在 String 上使用 ord 方法。

 s = "foo"
 s[0].ord

所以克隆那个家伙,修复它,然后向他发送一个拉取请求,这是开源方式:) 如果他没有回应,那么保留你的叉子,然后人们会使用它。

编辑

将第 27 行更改为:

  0.upto(text.length-1) {|i| text[i] = [text[i].ord ^round].pack('c')}
于 2011-02-05T05:18:06.037 回答
1

如果那个(一个操作)是唯一的问题,你不能稍微修改一下库吗?

于 2011-02-05T05:02:21.720 回答