Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
680 B
2
Indexable
Never
alphabet = list("abcdefghijklmnopqrstuvwxyz")
phrase = input("Give me a phrase:\n")
phrase.lower()
purpose = input("Do you want to encrypt or decrypt? ")
shift = int(input("How many places to shift: "))
newPhrase = ""
def caesar(phrase, shift):
    newPhrase = ""
    for i in phrase:
        if i == " ":
            newPhrase += " "
        if i in alphabet:
            x = alphabet.index(i)
            if x < 26-shift:
                newPhrase += alphabet[x+shift]
            else:
                newPhrase += alphabet[(x+shift)-26]
    return newPhrase
if purpose == "decrypt":
    print(caesar, phrase, -shift)
else:
    print(caesar(phrase, shift))
Leave a Comment