-1

我正在用 Python 编写一个非常粗糙的 Caesar Cipher,它可以很好地处理简单的消息,但是当我输入完整的字母表时,我在第 16 行出现错误,说存在索引错误:字符串索引超出范围。谁能帮我找出问题所在?这是我的代码:

    abc = "ABCDEFGHIJKLMNOPQRTUVWXYZ"
    m = str(input("Message: "))
    m = m + "~"
    m_t = m.index("~")
    o = int(input("Offset: "))
    e_m = "Encrypted Message: "
    for loop_counter in range(m_t):
        c = m[loop_counter]
        if c in abc:
            p = abc.index(c)
            p = p + o
            if 25 < p:
                p = p - 26
            elif 0 > p:
                p = p + 26
            n_c = abc[p]
            e_m = e_m + n_c
        else:
            e_m = e_m + c

    print(e_m)
4

1 回答 1

4

您的“abc”字符串长度为 25,您错过了“S”字母...

于 2015-05-03T14:28:26.217 回答