Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
678 B
2
Indexable
Never
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))
Leave a Comment