Untitled

 avatar
unknown
plain_text
a year ago
678 B
7
Indexable
alphabet = "abcdefghijklmnopqrstuvwxyz"
purpose = input("Do you want to encrypt or decrypt: ")
phrase = input("Enter a phrase you want to translate: \n")
shift = int(input("How many numbers do you want to shift: "))

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))
Editor is loading...
Leave a Comment