1

我找到了一个使用此功能的 ruby​​ 加密库。

def process(text)  
  0.upto(text.length-1) {|i| text[i] = text[i] ^ round}  
  text  
end

在 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

1 回答 1

2

试试text[i].ord ^ round。有关更多信息,请参阅使用 `?`(问号)在 Ruby 中获取 ASCII 字符代码失败

于 2011-02-04T16:32:05.253 回答