Untitled
unknown
plain_text
a year ago
680 B
6
Indexable
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))
Editor is loading...
Leave a Comment