Home β€Ί Secret Code School
πŸ” Module 05 Β· Intermediate

πŸ•΅οΈβ€β™€οΈ Secret Code School

Ever wanted to send a message only your best friend could read? Or wondered how video games keep your password safe even if hackers break in? You're in the right place! We're about to explore the amazing world of cryptographyβ€”the art of writing and solving secret codes. Ready to become a code-breaker? Let's go! πŸš€

πŸ“œ

The Art of Secret Messages

For thousands of years, people have used ciphers to hide information. A cipher is just a set of rules for scrambling a message. One of the oldest and simplest is the Caesar Cipher, named after Julius Caesar himself! All he did was shift each letter of the alphabet forward by a certain number of places. If the "key" was 3, 'A' would become 'D', 'B' would become 'E', and so on. Simple, but super effective for its time!

πŸ§ͺ TRY IT YOURSELF

The Secret Message Machine

Type a message below and use the slider to change the secret key. Watch how your message transforms in real-time! Can you send a coded message to a friend?

πŸ‘¨β€πŸ‘©β€πŸ‘§ Family Challenge: Grab some paper and create your own secret decoder wheel! It's a fun way to bring cryptography to life. Write a secret message for your family to solve at dinner tonight.

πŸŒͺ️

The Magic Blender: What is Hashing?

A Caesar Cipher is fun, but a modern computer could crack it in less than a second! For real security, like protecting your passwords, we use something called hashing.

Imagine a magic blender. You can put anything inβ€”a word, a sentence, or an entire book. You press "blend," and it gives you a short, unique code of random letters and numbers. That code is the "hash." Here's the magic part:
- The same input always creates the same hash. `password123` will always become the same jumble. - But change one tiny thing (`password124`), and you get a completely different jumble. - Most importantly, you can't un-blend it! You can't take the hash and figure out what the original message was. It's a one-way street.

⚑ HACKER CHALLENGE

Crack the Code!

A hacker has found a password hash, but not the password itself! We know the password is one of the four options below. Can you use the Hash Checker to find the right one?

Target Hash:

a5155462c1613a40

Potential Passwords: dinosaur, Tr3asure!, hunter2, password123

Your Calculated Hash:

---

βš™οΈ

Level Up: How Real Logins Work

So, how does this "magic blender" protect your real accounts on sites like Roblox or TomorrowHub? When you create an account, the website doesn't store your actual password. That would be too risky! Instead, it runs your password through a hash function and stores the hash.

When you log in, it takes the password you just typed, hashes it, and compares that new hash to the one it has stored. If they match, you're in! If a hacker ever steals the database, all they get is a list of hashes, not your actual passwords. But... even that can be dangerous if people use common passwords. Let's see why.

πŸ€– CODE-ALONG PROJECT

Build a Python Password Checker

Let's peek behind the curtain and see how a real login system might work using Python. We can't run the code here, but you can read through it to understand the logic that powers the internet!

Step 1: Import the Hashing Library

Python has a built-in library called `hashlib` for this exact job!

import hashlib

Step 2: The "User Database"

This is a fake database. Notice how we store the username and a HASHED password, never the real one.

# A dictionary pretending to be our user database
# The password for 'pan' is 'neverland_rules'
user_database = {
    "pan": "a516ba2084c88344e11c5914afd31d5a714c62e5"
}

Step 3: The Login Function

This is the core of our system. It takes a username and a password attempt, hashes the attempt, and compares it to what's in our database.

def check_password(username, password_attempt):
    # Get the stored hash for the user
    stored_hash = user_database.get(username)
    if not stored_hash:
        return "❌ User not found!"

    # Hash the password attempt using the same algorithm (sha1)
    attempted_hash = hashlib.sha1(password_attempt.encode()).hexdigest()

    # Compare the hashes!
    if attempted_hash == stored_hash:
        return "βœ… Access Granted! Welcome, " + username
    else:
        return "❌ Access Denied! Wrong password."

# Let's test it!
print(check_password("pan", "neverland_rules")) # This will work!
print(check_password("pan", "wrongpassword"))   # This will fail!

πŸš€ Go Pro: Salting & Brute-Forcing

What if two people use the same password, like `123456`? Their hashes would be identical! Hackers use "rainbow tables" β€” giant lists of pre-made hashes for common passwords β€” to crack them instantly.

To stop this, we add a "salt". A salt is a random piece of data added to the password *before* hashing. So `password` + `salt123` gets hashed. Now, even if two people use the same password, their hashes will be different because they have different salts. This makes rainbow tables useless!

πŸ›‘οΈ Safety Check: A great way to see if your email or password has been part of a known data breach is a tool called "Have I Been Pwned?". Ask a parent before you use it. It's a powerful tool for checking your digital safety, and it's best to explore it together.

πŸ“š Learn More

← Back to Dashboard