-1

I am writing a very rough Caesar Cipher in Python and it works fine with simple messages, but when I enter the full alphabet in, I get a error on my 16th line, saying that there is an index error: string index out of range. Can anyone help me find out what's wrong? Here's my code:

    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)

1 Answers1

4

Your 'abc' string is 25 in length, you missed the "S" letter...

onekiloparsec
  • 2,013
  • 21
  • 32