Demo entry 6785681

caesar cipher

   

Submitted by anonymous on Mar 19, 2019 at 06:03
Language: Python 3. Code size: 577 Bytes.

ALPHABET = "abcdefghijklmnopqrstuvwxyz"

print("Welcome to the Caesar Cipher")
mode = input("Do you want to encrypt or decrypt (e/d): ")
message = input("What is your message: ")
key = int(input("How many letters to rotate by: "))
if mode == "d":
    key = -1 * key

for current_letter in message:
    if current_letter in ALPHABET:
        current_index = ALPHABET.index(current_letter)
        new_index = (current_index + key) % 26
        new_letter = ALPHABET[new_index]
        print(new_letter, end='')

    else:
        print(current_letter, end='')

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).