Day 8 of Python Bootcamp

Day 8 of Python Bootcamp

We have been tasked with creating a Caesar cipher program for encoding and decoding. This project presents some challenges and requires meticulous attention to detail and patience through each step. Fortunately, the instructor has provided clear guidance on the specific problems we need to address, which simplifies the process. As a result, we, as students, can concentrate primarily on solving these problems.

You are welcome to download the code for use in your own studies. This allows you to explore and experiment with the concepts at your own pace, enhancing your learning experience.

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']

print("""           
 ,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           
""")


def ceasar(text,shift,cipher_direction):
    if cipher_direction.lower() == 'encode':
        encoded_text = ''
        for letter in text:
            if letter in alphabet:
                letter_index = alphabet.index(letter)
                new_index = (letter_index + shift) % len(alphabet) 
                encoded_text += alphabet[new_index]
                
            else:
                encoded_text += letter
        print(f"The encoded text is {encoded_text}")
    else:
        decoded_text = ''
        for letter in text:
            if letter in alphabet:
                letter_index = alphabet.index(letter)
                new_index = (letter_index - shift) % len(alphabet) 
                decoded_text += alphabet[new_index]
                
            else:
                decoded_text += letter
        print(f"The encoded text is {decoded_text}")

should_continue = True
while should_continue:
    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"))
    ceasar(text,shift,direction)
    result = input("Type 'yes' if you want to go again. Otherwise type 'no'.\n")
    if result.lower() == 'no':
        should_continue = False
    elif result.lower() == 'yes':
        should_continue = True
        

要查看或添加评论,请登录

King Mhar Bayato的更多文章

  • Creating Automated Birthday Greetings

    Creating Automated Birthday Greetings

    In today’s digital age, automating routine tasks can save time and add a personal touch to interactions. One such task…

    1 条评论
  • Creating a Local Password Manager Using Python and Tkinter

    Creating a Local Password Manager Using Python and Tkinter

    Managing passwords for various accounts can be daunting in today's digital age. This challenge led me to follow a…

    2 条评论
  • Testing the tkinter libraries

    Testing the tkinter libraries

    I'm on day 27 of my online course and just learned about arguments and kwargs. These concepts are beneficial for…

  • Part 1 of Building a Snake Game ( DAY 22 )

    Part 1 of Building a Snake Game ( DAY 22 )

    After an intense 20-day learning streak in the Python BootCamp, I took a much-needed three-week break. I was exhausted,…

  • Day 15, Coffee Project

    Day 15, Coffee Project

    Day 15 of my course, and my final project for the beginner class is to simulate a coffee vending machine. The…

  • Building a Follower Comparison Game in Python

    Building a Follower Comparison Game in Python

    In this tutorial, we'll walk through creating an engaging follower comparison game using Python. The game uses random…

  • Guess the Number

    Guess the Number

    The instructor tested our knowledge by assigning us a task to develop specific programs. Surprisingly, I managed to…

  • The Basic Blackjack or 21 in Python

    The Basic Blackjack or 21 in Python

    In developing a mini blackjack game, I first used the teacher's flowchart to outline the game's logic, ensuring clarity…

  • Day 10 of python boot camp

    Day 10 of python boot camp

    In this Python boot camp session, the main project revolves around creating a program known as the "secret auction…

  • Building 'Hangman': A Developer's Experience at an Online Bootcamp

    Building 'Hangman': A Developer's Experience at an Online Bootcamp

    During a seven-day online boot camp, a novice programmer embarked on a journey to create a mini-game called "Hangman."…

社区洞察

其他会员也浏览了