Cryptography: Symmetric, Asymmetric and Hashing Guide.
Cryptography is the science of keeping information secret and trustworthy in the presence of adversaries. It scrambles readable plaintext into unreadable ciphertext so that only someone with the right key can read it, and it provides tools to prove a message has not been altered. Every login, payment, and private message you send depends on it.
It matters because the internet is an open wire: anything you send can be copied by strangers in between. Cryptography is what makes online banking, private chats, and software updates possible at all. Understanding its three pillars — symmetric encryption, asymmetric encryption, and hashing — is the foundation of all computer security.
Key Concepts
- Plaintext / ciphertext: the original message versus its scrambled form.
- Key: the secret value that controls encryption and decryption. Longer keys mean more guessing work for attackers.
- Symmetric encryption: one shared secret key encrypts and decrypts. Fast, but both sides must somehow share the key safely. Example: AES-256.
- Asymmetric encryption: a public key encrypts, a matching private key decrypts. No secret needs sharing in advance. Example: RSA.
- Hashing: a one-way function turning any input into a fixed-size fingerprint. You cannot reverse it, and even a one-bit change avalanches the output. Example: SHA-256.
- Digital signature: a hash encrypted with a private key — proves who wrote the message and that it is unaltered.
- Key exchange: methods like Diffie–Hellman that let two strangers agree on a secret key over a public channel.
Formulas
- RSA key generation: pick primes p and q; n = p·q; φ(n) = (p−1)(q−1). Choose e with gcd(e, φ(n)) = 1; compute d so that e·d ≡ 1 (mod φ(n)). (e, n) is public, (d, n) is private.
- RSA encryption: C = M^e mod n. RSA decryption: M = C^d mod n. Works because of Euler's theorem; valid for messages M smaller than n.
- Symmetric strength: AES-256 has 2^256 ≈ 1.16 × 10^77 possible keys — brute force is physically infeasible.
- Hash property: SHA-256 always outputs 256 bits (64 hex characters) whether the input is one word or a whole movie.
Worked Example
Toy RSA with p = 3, q = 11:
- n = 3 × 11 = 33; φ(n) = 2 × 10 = 20.
- Choose e = 3 (gcd(3, 20) = 1). Find d with 3·d ≡ 1 (mod 20) → d = 7, since 21 ≡ 1 (mod 20).
- Encrypt message M = 5: C = 5³ mod 33 = 125 mod 33 = 26.
- Decrypt: M = 26⁷ mod 33. Since 26 ≡ −7 (mod 33), (−7)⁷ = −823543, and −823543 mod 33 = 5. The original message 5 returns.
Real RSA uses primes hundreds of digits long, but the mathematics is exactly this — modular arithmetic with a trapdoor that only the private key can open.
Common Misconceptions
- "Encryption means nobody can ever read it." It means reading it is computationally infeasible — unless the key leaks, is weak, or is stolen. Key management is where systems usually fail.
- "Hashing and encryption are the same." Encryption is reversible with a key; hashing is one-way by design. Passwords are hashed, messages are encrypted.
- "I invented my own cipher — it's unbreakable." Almost certainly not. Use vetted standards like AES and RSA; custom cryptography fails in ways experts take years to spot.
Real-World Applications
- HTTPS: asymmetric key exchange sets up a symmetric AES session that encrypts every page you load.
- Messaging apps: end-to-end encryption means only sender and receiver hold the keys.
- Passwords: servers store hashes (with salt), never plaintext passwords.
- Software updates: digital signatures prove an update truly came from the vendor and was not tampered with.
Cryptography's three pillars each solve a different problem: symmetric encryption for speed, asymmetric encryption for safe key sharing, and hashing for integrity. The math is public and proven — security comes from secret keys, not secret algorithms. Learn these ideas and every "secure" system you use will finally make sense.
Related blogs
- Network Security and Firewalls: Complete Beginner's Guide
- Web Security: XSS, SQL Injection and CSRF For students.
- Malware, Viruses and Ransomware Analysis Basics Guide.
- Ethical Hacking Basics: Complete Beginner's Guide Guide.
- Intrusion Detection Systems (IDS): Complete Beginner's Guide
- Digital Forensics Basics: Complete Beginner's Guide