This file contains hidden or 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
| # captcha_app.py | |
| # Simple CAPTCHA demo using `captcha` and Flask | |
| # NOTE: For lab/demo only. Do not use this exact secret_key or plaintext keys in production. | |
| from flask import Flask, render_template_string, request, session | |
| from captcha.image import ImageCaptcha | |
| import random, string, io, base64 | |
| app = Flask(__name__) | |
| app.secret_key = "change_this_in_lab" # replace with secure random key for real use |
This file contains hidden or 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
| # password_cracker.py | |
| import hashlib | |
| def try_crack(hashfile="test_hashes.txt", wordlist="wordlist.txt"): | |
| targets = [] | |
| with open(hashfile) as f: | |
| for line in f: | |
| salt_hex, h = line.strip().split(":") | |
| targets.append((bytes.fromhex(salt_hex), h)) |
This file contains hidden or 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
| # generate_hashes.py | |
| import hashlib | |
| import os | |
| def hash_password(password, salt=None): | |
| if salt is None: | |
| salt = os.urandom(8) # 8 bytes salt for demo | |
| h = hashlib.sha256(salt + password.encode()).hexdigest() | |
| return salt.hex(), h |
This file contains hidden or 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
| # Experiment 2: Demo and Practice on Crypto Library | |
| from cryptography.fernet import Fernet | |
| # Step 1: Generate a key | |
| key = Fernet.generate_key() | |
| print("Encryption Key:", key) | |
| # Step 2: Initialize Fernet object | |
| cipher = Fernet(key) |
This file contains hidden or 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
| # substitution_cipher.py | |
| import string | |
| # Caesar Cipher | |
| def caesar_encrypt(plaintext, shift): | |
| plaintext = plaintext.upper() | |
| alphabet = string.ascii_uppercase | |
| ciphertext = "" | |
| for ch in plaintext: | |
| if ch in alphabet: |