意外的keyword_end,预期的输入结束

时间:2014-02-20 17:05:25

标签: ruby encryption

我创建了一个方法,它应该使用附加键来加密并根据输入变量(文本)返回一个文本块。每当我通过CMD运行代码时,它会在第42行返回语法错误:意外的keyword_end,预期的输入结束。这是该方法的所有代码。

def add_en(text)
    print "Do you know the key?(y/n) "
    key_known = gets.chomp.downcase!

    if key_known == "y"
        print "Enter the key: "
        key = gets.chomp
        textone = text.delete(" ")
        stext =  textone.split(//)
        stext.each do |x|
            a = x.chr.upcase
            #puts a
            a.each_byte do |z|
                z -= 64
                z += key
                z = z % 26
                z += 65
                print z.chr
            end
        end
    elsif key_known == "n"
        puts "That's okay. I have a solution!"
        sleep(2)

        for key in (1..26) do
            textone = text.delete(" ")
            stext =  textone.split(//)

            stext.each do |x|
                a = x.chr.upcase
                #puts a

                a.each_byte do |z|
                    z -= 64
                    z += key
                    z = z % 26
                    z += 65
                    print z.chr
                end
            end
        end

        print "\n"
    end
end
#print "\n"
end

我做错了什么?

1 个答案:

答案 0 :(得分:4)

最后还有一个end

    end
    print "\n"
  end
end # <- This one
#print "\n"
end

删除它。 =)