From 893c119b3b17f1cd1bf9a0d490c222c47d504503 Mon Sep 17 00:00:00 2001 From: Vivek <92520077+sahutheboss@users.noreply.github.com> Date: Sat, 8 Oct 2022 18:37:30 +0530 Subject: [PATCH] Created caesar_cipher.py code to encode your passage and decrypt your message --- Python/caesar_cipher.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Python/caesar_cipher.py diff --git a/Python/caesar_cipher.py b/Python/caesar_cipher.py new file mode 100644 index 00000000..de4a92f8 --- /dev/null +++ b/Python/caesar_cipher.py @@ -0,0 +1,37 @@ +print(''' + + ███████████████████████████████████████████████████████████████████████ + █─▄▄▄─██▀▄─██▄─▄▄─█─▄▄▄▄██▀▄─██▄─▄▄▀███─▄▄▄─█▄─▄█▄─▄▄─█─█─█▄─▄▄─█▄─▄▄▀█ + █─███▀██─▀─███─▄█▀█▄▄▄▄─██─▀─███─▄─▄███─███▀██─███─▄▄▄█─▄─██─▄█▀██─▄─▄█ + ▀▄▄▄▄▄▀▄▄▀▄▄▀▄▄▄▄▄▀▄▄▄▄▄▀▄▄▀▄▄▀▄▄▀▄▄▀▀▀▄▄▄▄▄▀▄▄▄▀▄▄▄▀▀▀▄▀▄▀▄▄▄▄▄▀▄▄▀▄▄▀ + + ''') + + +alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] +end_task="Yes" +while end_task=="Yes": + direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n") + text = input("Type your message:\n").lower() + shift = int(input("Type the shift number:\n")) + shift =shift % 25 + + def caesar(start_text, shift_amount, cipher_direction): + end_text = "" + for letter in start_text: + if letter not in alphabet: + end_text += letter + else : + position = alphabet.index(letter) + if cipher_direction == "decode": + shift_amount = -abs(shift_amount) + new_position = position + shift_amount + new_letter = alphabet[new_position] + end_text += new_letter + print(f"The {direction}d text is {end_text}") + + caesar(start_text=text, shift_amount=shift, cipher_direction=direction) + end_task=input("Type 'Yes' to go again ,otherwise type 'No'\n") + if end_task=="No": + break +print("Thanks for using 'CAESAR CIPHER' ,Have a nice day!")