-
-
Save armando-adorno/ddb252b6aabcdd5e41e2f1a66dfebfcd to your computer and use it in GitHub Desktop.
Python Bootcamp Day 8: Caesar Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logo = """ | |
,adPPYba, ,adPPYYba, ,adPPYba, ,adPPYba, ,adPPYYba, 8b,dPPYba, | |
a8" "" "" `Y8 a8P_____88 I8[ "" "" `Y8 88P' "Y8 | |
8b ,adPPPPP88 8PP""""""" `"Y8ba, ,adPPPPP88 88 | |
"8a, ,aa 88, ,88 "8b, ,aa aa ]8I 88, ,88 88 | |
`"Ybbd8"' `"8bbdP"Y8 `"Ybbd8"' `"YbbdP"' `"8bbdP"Y8 88 | |
88 88 | |
"" 88 | |
88 | |
,adPPYba, 88 8b,dPPYba, 88,dPPYba, ,adPPYba, 8b,dPPYba, | |
a8" "" 88 88P' "8a 88P' "8a a8P_____88 88P' "Y8 | |
8b 88 88 d8 88 88 8PP""""""" 88 | |
"8a, ,aa 88 88b, ,a8" 88 88 "8b, ,aa 88 | |
`"Ybbd8"' 88 88`YbbdP"' 88 88 `"Ybbd8"' 88 | |
88 | |
88 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import art | |
print(art.logo) | |
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'] | |
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")) | |
def encrypt(text,shift): | |
'''The encrypt() function implement the Caesar Cipher encryption algorithm for secure message transmision.''' | |
##🐛Bug alert: What happens if you try to encode the word 'civilization'?🐛 | |
encrypted_word = "" | |
for letter in text: | |
encrypted_word += alphabet[alphabet.index(letter) + shift] | |
print(f"The encoded text is {encrypted_word}") | |
def decrypt(text,shift): | |
'''The decrypt() function implement the Caesar Cipher decryption algorithm for secure message transmision''' | |
decrypted_word = "" | |
for x in text: | |
decrypted_word += alphabet[alphabet.index(x) + 26 - shift] | |
print(f"The decoded text is {decrypted_word}") | |
def caesar(text,shift,direction): | |
'''The caesar() function implement the Caesar Cipher algorithm for secure message trasmision''' | |
if(direction == "encode"): | |
encrypt(text,shift) | |
elif(direction == "decode"): | |
decrypt(text,shift) | |
else: | |
print("Error") | |
caesar(text,shift,direction) | |
restart_program = input("\nWant Decode or Encode another message? \n\n1. Yes\n2. No\nEnter: ").lower() | |
if(restart_program == "yes" or restart_program == "1"): | |
restart = True | |
else: | |
restart = False | |
while(restart == True): | |
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")) | |
caesar(text,shift,direction) | |
restart_program = input("\nWant Decode or Encode another message? \n\n1. Yes\n2. No\nEnter: ").lower() | |
if(restart_program == "yes" or restart_program == "1"): | |
restart = True | |
else: | |
restart = False | |
print("Good Bye") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment