Basic Concepts & Terminology
Cryptography (from Greek: "secret writing") is the science and art of transforming messages to make them secure and immune to attacks. Know these definitions cold — they appear in every exam.
+ Key
(Ciphertext)
+ Key
Exam Tip: What Does Cryptography Protect?
Cryptography protects Confidentiality (encryption) and Integrity (hashing/MACs). It does NOT protect Availability — a DoS attack can still bring down an encrypted service.
Kerckhoffs's Principle
A fundamental rule in cryptography that all modern crypto systems follow.
The Core Rule
A cryptographic algorithm should be secure even if everyone knows how it works. The security of a cryptosystem must depend solely on the secrecy of the key — not the secrecy of the algorithm.
The encryption/decryption algorithm — anyone (including attackers) can know it.
Only the key is kept secret. The resistance of the cipher relies entirely on key secrecy.
AES (Advanced Encryption Standard) is fully public — anyone can read the algorithm. What makes your data safe is the 256-bit key that only you know. This is Kerckhoffs's Principle in action.
Classifying Cryptographic Systems
Cryptosystems are characterized along three independent dimensions:
🔑 By Number of Keys
- Same key for both encryption & decryption → Symmetric (Conventional) Encryption
- Different keys for encryption & decryption → Asymmetric (Public Key) Encryption
🔄 By Operation Type
- Substitution — each element (letter/bit) is mapped to another element
- Transposition / Permutation — elements are rearranged, not substituted
📦 By Plaintext Processing
- Block Cipher — processes one block of input at a time, produces output per block
- Stream Cipher — processes input bit by bit, produces output one element at a time
Classical Cipher Methods
🏛️ Caesar Cipher (Substitution)
Used by Julius Caesar in the 1st Century BC. The cipher alphabet is the plain alphabet shifted n spaces to the right.
Formula: Encrypt: E(x) = (x + n) mod 26 | Decrypt: D(x) = (x − n) mod 26
| Type | Text |
|---|---|
| Plaintext | "attack at dawn" |
| Ciphertext (shift=14) | "OHHOQY OH ROKB" |
E(a) = (1+14) mod 26 = 15 = "o" | D(O) = (15−14) mod 26 = 1 = "a"
🔁 ROT13 (Special Caesar)
A popular substitution cipher where each letter is replaced by the letter 13 positions ahead. Applying ROT13 twice returns the original. There are 26! ≈ 4×10²⁶ possible monoalphabetic substitutions.
Plaintext: "We love PSU" → Ciphertext: "Jr ybir CFH" (each letter shifted by 13)
🔡 Vigenère Cipher (Polyalphabetic Substitution)
Uses a keyword repeated to match the plaintext length. Each letter is shifted by the corresponding keyword letter — making frequency analysis much harder than Caesar.
| Field | Value |
|---|---|
| Plaintext | GEEKSFORGEEKS |
| Keyword | AYUSH (repeated → AYUSHAYUSHAYU) |
| Ciphertext | GCYCZFMLYLEIM |
Encryption: rows = plaintext, columns = key → intersection = cipher. Decryption: rows = key, find cipher, column = plain.
📋 One-Time Pad (Unbreakable!)
Invented in 1917 by Joseph Mauborgne and Gilbert Vernam. Uses a block of completely random shift keys (k₁, k₂, …, kₙ) — one per character — chosen uniformly at random.
Since each shift is random, every ciphertext is equally likely for any plaintext. This makes it absolutely unbreakable — the only theoretically perfect cipher.
Why It's Not Practical
The key must be as long as the message, truly random, never reused, and securely shared — making it impractical for most real-world use.
↔️ Transposition Cipher
Instead of substituting characters, transposition ciphers rearrange the positions of characters without changing the characters themselves. The letters stay the same — only their order changes.
Plaintext: HELLO → rearranged by key pattern → Ciphertext: LLEHO. Frequency analysis won't help because letter frequencies are preserved.
Symmetric vs Asymmetric Encryption
🔐 Symmetric Encryption
One shared secret key used for both encryption and decryption. Both sender and receiver must have the same key.
- Fast — almost 30,000× faster than asymmetric
- Key distribution is the major challenge
- DK(EK(P)) = P (decrypting ciphertext gives back plaintext)
- Also called: Private Key, Conventional, Secret Key encryption
🗝️ Shared Key
🗝️ Shared Key
🔑 Asymmetric Encryption (Public Key)
Two separate keys: a public key (shared openly) and a private key (kept secret). Used for confidentiality, authentication, or both.
- Public key = locks (encrypts)
- Private key = unlocks (decrypts)
- Slower than symmetric — but solves the key distribution problem
- Based on mathematical trapdoor one-way functions (e.g., factoring large primes)
Encrypt with receiver's-public-key-→-decrypt-with-receiver's private key. Sign with sender's-private-key-→-verify-with-sender's public key.
| Feature | Symmetric | Asymmetric |
|---|---|---|
| Keys | 1 shared secret key | 2 keys: public + private |
| Speed | ~30,000× faster | Much slower |
| Key Distribution | Difficult / Problem | Easy (public key is public) |
| Use Cases | Bulk data encryption | Key exchange, digital signatures |
| Exam Trick | Problem with symmetric = secure key distribution (from past exam) | |
Q: What is a problem with symmetric key encryption?
a) It is slower than asymmetric key encryption
b) Most algorithms are kept proprietary
c) Work factor is not a function of the key size
d) Secure distribution of the secret key ✅
Q: In public key cryptography…
a) Only the private key can encrypt and only the public key can decrypt
b) Only the public key can encrypt and only the private key can decrypt
c) The public key is used to encrypt and decrypt
d) If the public key encrypts, then only the private key can decrypt ✅
Hash Functions
A hash function is a special mathematical function that performs one-way encryption. Once processed, there is no feasible way to recover the plaintext from the hash output.
One-Way
You cannot reverse a hash to get the original plaintext. Plaintext → Hash is easy; Hash → Plaintext is computationally infeasible.
Fixed Length Output
The message digest (hash value) has a fixed length regardless of input size. "HELLO" and a 10GB file produce the same length hash.
No Two Same Hashes
Ideally, there is no feasible way to generate two different plaintexts that produce the same hash. When this breaks, it's a collision attack.
Common Uses of Hashing
- Storing computer passwords (never store plaintext passwords)
- Ensuring message integrity (detect tampering)
- Message Authentication Code (MAC) — hash + secret key to verify integrity and authenticity
- Digital signatures (hash the message, then sign the hash)
Why MAC?
Hash functions are public — anyone can run them. So we need a secret key combined with the hash to create a MAC, proving who sent the message and that it wasn't tampered with.
🔐 SHA — Secure Hash Algorithm
Developed by the NSA and approved as a federal standard by NIST.
| Version | Year | Digest Size | Status |
|---|---|---|---|
| SHA-1 | 1993 | 160 bits | ⚠️ Vulnerable to collision attacks — avoid |
| SHA-2 | 2002 | SHA-256 or SHA-512 | ✅ More secure than SHA-1 |
| SHA-3 | 2015 | 224, 256, 384, or 512 bits | ✅ Latest standard by NIST |
📋 MD — Message Digest
| Version | Year | Output | Notes |
|---|---|---|---|
| MD2 | 1989 | 128 bits | Vulnerable without checksum |
| MD4 | 1990 | 128 bits | Fast but subject to many attacks |
| MD5 | 1991 | 128 bits | Based on MD4 but more secure; slightly slower |
Collision Attack
A collision attack finds two different messages that hash to the same value — a loss of integrity. SHA-1 and MD5 are known to be vulnerable. Use SHA-256 or higher.
Attacks on Cryptosystems
The goal of an attacker is to recover the key (not just individual messages), compromising all future and past ciphertexts. Two general approaches:
1. Cryptanalysis
Mathematical/analytical attacks that exploit weaknesses in the algorithm or known information. The encryption algorithm is assumed to be known for all attacks.
2. Brute Force
Try every possible key until an intelligible plaintext is found. Effectiveness is proportional to key size — bigger keys = exponentially longer attack time.
Cryptanalysis Attack Types
| Attack Type | What the Attacker Knows | Goal | Difficulty |
|---|---|---|---|
| Ciphertext Only | Only the ciphertext (C₁, C₂, …). Knowledge of plaintext is minimal. | Find key K and/or plaintexts | Hardest for attacker |
| Known Plaintext | Some plaintext-ciphertext pairs (P₁,C₁), (P₂,C₂), … | Find key K | Moderate |
| Chosen Plaintext | Plaintext-ciphertext pairs AND can choose which plaintexts to encrypt | Find key K | Easier for attacker |
| Chosen Ciphertext | Can choose ciphertexts to decrypt; has access to a decryption oracle | Find key K | Easiest for attacker |
Brute Force: Key Size vs Time
| Key Size | Possible Keys | Time @ 1 dec/μs | Time @ 10⁶ dec/μs |
|---|---|---|---|
| 32 bits | 4.3 × 10⁹ | 35.8 minutes | 2.15 milliseconds |
| 56 bits (DES) | 7.2 × 10¹⁶ | 1,142 years | 10.01 hours ⚠️ Broken |
| 128 bits (AES) | 3.4 × 10³⁸ | 5.4 × 10²⁴ years | 5.4 × 10¹⁸ years ✅ |
| 168 bits (3DES) | 3.7 × 10⁵⁰ | 5.9 × 10³⁶ years | 5.9 × 10³⁰ years ✅ |
📊 Frequency Analysis (Attack on Substitution Ciphers)
Letters in natural languages are not uniformly distributed. In English, 'E' appears ~13% of the time, 'T' ~9%, etc. By analyzing which ciphertext letters appear most often, an attacker can deduce the substitution pattern and break the cipher.
In a ciphertext-only attack on a Caesar cipher, if 'X' appears most frequently, the attacker guesses X=E (the most common English letter), calculates the shift, and decrypts the message — no key needed!
Why Vigenère Resists Frequency Analysis
The Vigenère cipher uses different shifts for each letter, so the same plaintext letter can produce different ciphertext letters — hiding frequency patterns.
Encryption vs Digital Signatures
🔐 Encryption (Confidentiality)
Sender encrypts
Using the receiver's public key
Receiver decrypts
Using their own private key
✍️ Digital Signature (Authentication)
Signer signs
Using their own private key
Anyone verifies
Using the sender's public key
Q: What is used to CREATE a digital signature?
a) The receiver's public key
b) The sender's public key
c) The sender's-private-key-✅
d)-The-receiver's public key
Memory rule: Sign with private, verify with public.
Block Ciphers & Diffusion/Confusion
🔀 Diffusion
Spreads the influence of a single plaintext character over many ciphertext characters. Makes it hard to see the relationship between plaintext structure and ciphertext structure.
Q: In a block cipher, diffusion… → B) Spreads the influence of a plaintext character over many ciphertext characters ✅
🎭 Confusion
Conceals the connection between the ciphertext and the plaintext (and the key). Usually implemented using nonlinear S-boxes (substitution boxes).
Memory Trick: Diffusion vs Confusion
Diffusion = spread (one letter affects many). Confusion = hide (conceal the relationship). Both are required for a secure block cipher.
Exam Tips & Tricks 🎯
Crypto Protects CIA (Partial)
Cryptography protects Confidentiality (encryption) and Integrity (hashing). It does NOT protect Availability.
Key Direction Rules
Encrypt for privacy → receiver's-public-key.-Sign-for-authentication-→-sender's private key. Verify signature → sender's public key.
Speed
Symmetric encryption is ~30,000× faster than asymmetric. If a question mentions speed, think symmetric.
One-Time Pad = Unbreakable
The only theoretically unbreakable cipher. But the key must be as long as the message and never reused — making it impractical.
SHA Versions Order
SHA-1 (160 bits, broken) → SHA-2 (256/512, secure) → SHA-3 (2015, latest). For passwords, never use SHA-1 or MD5.
Kerckhoffs's Principle in One Line
Algorithm public, key secret. Security comes from key secrecy, not algorithm secrecy. Used by AES, RSA, all modern systems.
Symmetric Problem = Key Distribution
The classic weakness of symmetric crypto is how do you securely share the key? Asymmetric crypto solves this with public keys.
Block vs Stream
Block cipher = processes fixed-size chunks. Stream cipher = processes one bit/byte at a time. Block is more common (AES is a block cipher).
Quick Reference — Everything at a Glance
| Topic | Key Point |
|---|---|
| Cryptography protects | Confidentiality + Integrity ONLY (not Availability) |
| Kerckhoffs's Principle | Algorithm = public; Key = secret |
| Symmetric | 1 shared key; fast (~30,000× faster); key distribution = problem |
| Asymmetric | Public + private keys; slower; solves key distribution |
| Encrypt for privacy | Use receiver's PUBLIC key |
| Sign (digital signature) | Use sender's PRIVATE key |
| Verify signature | Use sender's PUBLIC key |
| Caesar Cipher | E(x) = (x+n) mod 26; shift cipher; breakable by frequency analysis |
| Vigenère Cipher | Polyalphabetic substitution; keyword repeated; resists frequency analysis |
| One-Time Pad | Unbreakable; key = random, length of message, never reused |
| Hash = One-Way | Cannot reverse; fixed-length output; used for passwords + integrity |
| SHA-1 | 160 bits; vulnerable to collision attacks — avoid |
| SHA-2/3 | SHA-256/512; current standard |
| Collision Attack | Two different inputs → same hash → loss of integrity |
| MAC | Hash + secret key = proves integrity AND authenticity |
| Ciphertext Only Attack | Hardest; attacker has only ciphertext |
| Chosen Ciphertext Attack | Easiest for attacker; has decryption oracle |
| Diffusion | Spreads one plaintext character influence over many ciphertext chars |
| Confusion | Conceals plaintext-ciphertext relationship; uses S-boxes |
| Brute Force | Try all keys; 128-bit AES = effectively unbreakable |
| Frequency Analysis | Breaks substitution ciphers using letter frequency patterns |