Cryptography is the practice of securing communication and data using mathematical algorithms (encryption, decryption, hashing, digital signatures). Core goals: confidentiality (data unreadable without key), integrity (data not tampered), authentication (verify sender), non-repudiation (sender cannot deny). Modern cryptography underpins HTTPS (TLS/SSL), VPNs, digital signatures, blockchain, password hashing (bcrypt, Argon2).
Cryptography Statistics: 95% of web traffic uses TLS/SSL (HTTPS). AES-256 is unbroken (military-grade). 2^256 possible keys (more than atoms in universe). Quantum computing threatens RSA-2048 (Shor's algorithm).
Core cryptographic primitives:
Same key for encryption and decryption. Fast (1-10 Gbps). Key distribution problem. Algorithms: AES (AES-128, AES-256, AES-GCM), ChaCha20, DES (broken), 3DES (deprecated).
Public key encrypts, private key decrypts. Slow (10-100 Mbps). Solves key distribution. Algorithms: RSA (RSA-2048, RSA-4096), ECC (ECDSA, Ed25519, X25519).
Fixed-size output (256 bits). Collision-resistant, preimage-resistant. Password hashing: bcrypt, Argon2, PBKDF2. Data integrity: SHA-256, SHA-3, BLAKE2, SHA-1 (broken).
Combine asymmetric + symmetric (TLS/SSL). Asymmetric for key exchange, symmetric for data encryption. Example: RSA + AES.
// Symmetric encryption (AES-256-GCM - recommended)
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
import os
key = os.urandom(32) # 256-bit key
iv = os.urandom(12) # 96-bit IV (GCM)
cipher = Cipher(algorithms.AES(key), modes.GCM(iv))
encryptor = cipher.encryptor()
ciphertext = encryptor.update(b"secret data") + encryptor.finalize()
// Asymmetric encryption (RSA-2048 - SSL/TLS)
openssl genrsa -out private.pem 2048
openssl rsa -in private.pem -pubout -out public.pem
// Hash function (SHA-256)
echo -n "password123" | sha256sum
// Output: ef92b778bafe771e89245b89ecbc08a44a4e166c06659911881f383d4473e94f
// Password hashing (bcrypt - recommended)
import bcrypt
salt = bcrypt.gensalt(rounds=12) # Cost factor 12
hashed = bcrypt.hashpw(b"password123", salt)
// Digital signature (ECDSA)
openssl ecparam -name secp256k1 -genkey -out private.key
openssl ec -in private.key -pubout -out public.key
Try every possible key. AES-256: 2^256 possibilities (infeasible). Quantum computing (Grover's algorithm) reduces to 2^128 (still infeasible).
Timing attack (cache timing, branch prediction), power analysis (SPA, DPA), electromagnetic radiation. Mitigation: constant-time algorithms.
Find two different inputs with same hash. SHA-1 broken (Google shattered attack, 2020). SHA-256 collision-resistant (2^128 operations).
Attacker intercepts key exchange (Diffie-Hellman). Mitigation: digital signatures, certificate pinning, TLS with certificate validation.
Shor's algorithm breaks RSA, ECC (factorization, discrete log). Post-quantum cryptography: Kyber (NIST PQC winner), Dilithium, Falcon, SPHINCS+.
Exploits error messages to decrypt ciphertext. Mitigation: use authenticated encryption (GCM, ChaCha20-Poly1305).
TLS/SSL protocol implementation. Generate keys (RSA, ECC), certificates (X.509), encrypt/decrypt files (enc), hash (dgst).
OpenPGP implementation. Encrypt/decrypt files, sign/verify signatures, key management (--gen-key, --export, --import).
Crack password hashes (MD5, SHA1, bcrypt, NTLM). GPU acceleration (NVIDIA CUDA, AMD OpenCL).
Password hash cracker (MD5, SHA, bcrypt, NTLM, Kerberos). Wordlist mode, incremental mode.
High-level Python cryptography library (AES, RSA, ECDSA, X.509).
This demonstration simulates AES-256 encryption and decryption:
This is a simulated demonstration. Real AES-256 is unbroken (military-grade). Use authenticated encryption (AES-GCM, ChaCha20-Poly1305). Never roll your own crypto (use standard libraries).
Use AES-256-GCM (authenticated encryption) instead of AES-CBC. Never use DES, 3DES, RC4, MD5, SHA-1 (broken).
Store keys in KMS (AWS KMS, Azure Key Vault) or HSM (Hardware Security Module). Never hardcode keys in source code.
Use bcrypt (cost factor 12+), Argon2id (recommended for new systems). Never use MD5 or SHA1 for passwords.
Use constant-time comparison (crypto.timingSafeEqual). Avoid branching based on secret data.
Best Practice - Use Standard Algorithms + Proper Key Management: Use AES-256-GCM (authenticated encryption) or ChaCha20-Poly1305. Use Argon2id or bcrypt for password hashing. Use TLS 1.3 (disable TLS 1.0, 1.1). Store keys in KMS/HSM (AWS KMS, Azure Key Vault). Never roll your own crypto (use libsodium, OpenSSL, cryptography.io).
Cryptography is legal in most countries. Some countries restrict encryption exports (EAR, Wassenaar Arrangement).
Cryptography is legal in most countries for legitimate purposes (privacy, security). However, using cryptography to hide illegal activities (child exploitation, terrorism) is illegal. Export restrictions apply to certain countries (China, Russia, Iran, North Korea).
Important: Use cryptography ethically and legally. Comply with export controls if distributing encryption software.
US government cryptographic standards (AES, SHA, RSA, ECDSA, key management).
High-level cryptographic library (AES-256-GCM, ChaCha20-Poly1305, Argon2, Ed25519).
Free introduction to cryptography (symmetric, asymmetric, hash, TLS).