Caesar Cipher

caesar , cipher , string , algorithms

Siege-alesia-vercingetorix-jules-cesar


def cipher(a_string, key):
    uppercase = ABCDEFGHIJKLMNOPQRSTUVWXYZ
    lowercase = abcdefghijklmnopqrstuvwxyz
    encrypt = ''
    for x in a_string:
        if x in uppercase:
            print(uppercase.index(x))

            # (1)
            new = (uppercase.index(x) + key) % 26

			# (2)
            encrypt += uppercase[new]
        elif x in lowercase:
            print(lowercase.index(x))
            new = (lowercase.index(x) + key) % 26
            encrypt += lowercase[new]
        else:
            encrypt += x
    print("Cipher text: ", encrypt)
    return encrypt

a_string = input("Enter a name")
key = input("Enter a key (must be integer) ")
cipher(a_string, int(key))

How it works #

Can’t understand what i wrote here? #

Thanks for reading :) #