getc方法有什么作用?

时间:2014-02-13 20:16:51

标签: ruby

getc方法在ruby中做了什么?我找到了这段代码:

class XOREncrypt
  def initialize(inputfile, password, outputfile)
    input = File.open(inputfile,"r")
    pass_array = password.split(//)
    output = File.new(outputfile,"w")
    i = 0
    while c = input.getc
      pass_char = pass_array[i]
      xor = c.chr[0] ^ pass_char[0]
      output.print(xor.chr)
      i+=1
      if i == (pass_array.size - 1)
        i = 0
      end
    end
    input.close
    output.close
  end
 end

puts "Filename for Input : "
inputfile = gets
puts "Insert Password : "
password = gets
puts "Filename for Output : "
outputfile = gets
XOREncrypt.new(inputfile.chomp, password.chomp, outputfile.chomp)

getc方法在ruby中做了什么?我用Google搜索,但没有结果。

1 个答案:

答案 0 :(得分:0)

从文件中读取下一个8位。

http://ruby-doc.org/core-1.8.6/IO.html#method-i-getc