Skip to content

Lakshitpythondevloper/Ceasor-Cipher-Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—οΈ Ceasor Cipher Game

Welcome to the Ceasor Cipher Game!
This is a fun, interactive Python project that lets you learn about and play with the classic Caesar Cipher encryption technique. Encrypt your secret messages, challenge your friends to decode them, and explore the basics of cryptographyβ€”all in one game! πŸ”’βœ¨


🎯 Features

  • Encrypt & Decrypt: Encode your messages with a shift of your choice and decode messages from friends.
  • User-Friendly Interface: Simple, clear prompts and outputs for beginners and enthusiasts alike.
  • Custom Shift Amount: Choose how secret you want your message to be.
  • Replayable: Play as many rounds as you like!

πŸš€ Getting Started

1. Clone the Repository

git clone https://github.com/Lakshitpythondevloper/Ceasor-Cipher-Game.git
cd Ceasor-Cipher-Game

2. Run the Game

Make sure you have Python 3.x installed.
To start the game, run:

python ceasor_cipher_game.py

πŸ“ How to Play

  1. Select an option: Encrypt or decrypt a message.
  2. Enter your message: Type in the text you want to encode or decode.
  3. Set the shift: Pick the number of positions each letter will be moved in the alphabet.
  4. See the result: Your encrypted or decrypted message appears!

🧠 What is the Caesar Cipher?

The Caesar Cipher is one of the oldest known encryption techniques. It works by shifting each letter in your message by a set number of places in the alphabet.
For example, with a shift of 3:
A ➑️ D, B ➑️ E, C ➑️ F, … and so on.


πŸ“‚ Project Structure

Ceasor-Cipher-Game/
β”‚
β”œβ”€β”€ ceasor_cipher_game.py   # Main game logic
β”œβ”€β”€ README.md               # This beautiful file!
└── LICENSE                 # License info

Explanation of code πŸ“–: -

πŸ–₯️ Code Explanation

1. ASCII Art Banner

print(r'''
________  _______   ________  ________  _______  _________        ________  ________  ________  _______          
|\   ____\|\  ___ \ |\   ____\|\   __  \|\  ___ \|\___   ___\     |\   ____\|\   __  \|\   ___ \|\  ___ \         
\ \  \___|\ \   __/|\ \  \___|\ \  \|\  \ \   __/\|___ \  \_|     \ \  \___|\ \  \|\  \ \  \_|\ \ \   __/|        
 \ \_____  \ \  \_|/_\ \  \    \ \   _  _\ \  \_|/__  \ \  \       \ \  \    \ \  \\\  \ \  \ \\ \ \  \_|/__      
  \|____|\  \ \  \_|\ \ \  \____\ \  \\  \\ \  \_|\ \  \ \  \       \ \  \____\ \  \\\  \ \  \_\\ \ \  \_|\ \     
    ____\_\  \ \_______\ \_______\ \__\\ _\\ \_______\  \ \__\       \ \_______\ \_______\ \_______\ \_______\    
   |\_________\|_______|\|_______|\|__|\|__|\|_______|   \|__|        \|_______|\|_______|\|_______|\|_______|    
   \|_________|      
''')
  • Uses raw string (r'') to display an ASCII art title banner
  • Creates an attractive visual interface for users

2. Alphabet Definition

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']
  • Defines a list containing all lowercase letters of the English alphabet
  • Used as the reference for shifting letters during encryption/decryption

3. Encryption Function

def encrypt(originaltext, shift_amount):
    Ceaser = ""
    for letters in originaltext:
        shifted_postion = alphabet.index(letters) + shift_amount
        shifted_postion %= len(alphabet)
        Ceaser += alphabet[shifted_postion]
    print(f"Here is a encoded text : {Ceaser}")
  • Takes two parameters: the original text and the shift amount
  • For each letter:
    • Finds its position in the alphabet
    • Adds the shift amount
    • Uses modulo to handle wrapping around the alphabet
    • Builds the encrypted string
  • Prints the final encrypted text

4. Decryption Function

def decode(originaltext, shift_amount):
    Ceaser = ""
    for letters in originaltext:
        shifted_postion = alphabet.index(letters) - shift_amount
        Ceaser += alphabet[shifted_postion]
    print(f"Here is a decode text : {Ceaser}")
  • Takes two parameters: the encoded text and the shift amount
  • Reverses the encryption process by:
    • Finding each letter's position
    • Subtracting the shift amount
    • Building the decrypted string
  • Prints the decrypted text

5. Main Program Loop

restart = True
while restart:
    direction = input("Type 'encode' to encrypt, type 'decode' to decrypt: ").lower()
    text = input("Type your message: ").lower()
    shift = int(input("Type shift number: "))
  • Creates an interactive loop for multiple operations
  • Prompts user for:
    • Operation type (encode/decode)
    • Message to process
    • Shift value

6. Operation Selection

    if direction == "encode":
        encrypt(text, shift)
        restart_request = input("Do you want to restart the game Type Y or N: ")
    elif direction == "decode":
        decode(text, shift)
        restart_request = input("Do you want to restart the game Type Y or N: ").capitalize()
    else:
        print("Invalid input, please try again.")
  • Handles user input validation
  • Calls appropriate function based on user choice
  • Asks if user wants to continue

7. Restart Logic

    if restart_request == 'N':
        restart = False
    else:
        restart = True
        print("Thank you for playing the game")
  • Controls program flow based on user's restart choice
  • Provides feedback to user

πŸš€ How to Use

  1. Run the program
  2. Choose 'encode' or 'decode'
  3. Enter your message (lowercase letters only)
  4. Enter the shift number
  5. View the result
  6. Choose to continue or exit

πŸ“ Example

Type 'encode' to encrypt, type 'decode' to decrypt: encode
Type your message: hello
Type shift number: 3
Here is a encoded text: khoor

⚠️ Limitations

  1. Only supports lowercase letters
  2. No support for:
    • Spaces
    • Numbers
    • Special characters
    • Uppercase letters

🀝 Contributing

Contributions are welcome!
If you have suggestions or improvements, feel free to fork this repository and submit a pull request.


πŸ“œ License

This project is licensed under the MIT License.


πŸ™‹β€β™‚οΈ Author

Developed by Lakshitpythondevloper

If you enjoy this project, please ⭐️ the repo to show your support!


β€œCryptography is the ultimate puzzle!” 🧩

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages