Cryptography keeps data secret and trustworthy by transforming it with keys. This article builds the vocabulary — security goals, attacks, classical ciphers, symmetric versus asymmetric encryption, block and stream modes, hashes, MACs and signatures — that every later security topic and many PSC questions use.
High-yield 65 minSyllabus: “Symmetric and asymmetric encryption”
Mark as
The idea in one minute
Picture a box with a lock. With symmetric encryption, sender and receiver hold identical keys to the same lock — quick to use, but every pair of people must first meet to swap keys. With asymmetric encryption, the owner hands out open padlocks (public keys) that anyone can snap shut, while keeping the only key that opens them (the private key). A hash is a fingerprint of the contents, and a digital signature is a wax seal only the owner can press but anyone can recognise.
Key points — the night-before list
Plaintext + key → encryption → ciphertext → decryption → plaintext. Cryptography designs ciphers, cryptanalysis breaks them; together they form cryptology. Kerckhoffs: only the key need be secret.
Security goals: confidentiality, integrity, availability (the CIA triad) plus authentication, non-repudiation and access control — the security services of ITU-T X.800.
Passive attacks (eavesdropping, traffic analysis) are hard to detect, so prevent them; active attacks (masquerade, replay, modification, denial of service) are detected and recovered from.
Substitution replaces symbols (Caesar, monoalphabetic, Playfair, Vigenère, one-time pad); transposition reorders them (rail fence, columnar); product ciphers chain both — the basis of DES and AES.
Symmetric: one shared key, fast, n(n−1)/2 keys for n users (DES, AES, IDEA). Asymmetric: public/private pair, slow, 2n keys (RSA, ECC, Diffie–Hellman).
Modes: ECB leaks repeated blocks; CBC chains blocks with an IV; CFB, OFB and CTR make a block cipher act as a stream cipher. CTR is fully parallel; OFB/CTR errors don't spread.
Shannon (1949): confusion hides the key–ciphertext link (S-boxes); diffusion spreads each plaintext bit over many ciphertext bits (permutations). Only the one-time pad is unconditionally secure.
Hashes are fixed-size, one-way, collision-resistant digests: MD5 128, SHA-1 160, SHA-256 256 bits. A MAC/HMAC adds a key (integrity + origin authentication); a signature adds non-repudiation.
01The language of cryptography
Cryptography is the science of protecting information by transforming it so that only the intended parties can use it. Every scheme has the same moving parts, so it pays to learn the words precisely — many PSC questions hinge on one of them.
Plaintext (P or M) — the original, readable message.
Ciphertext (C) — the scrambled output that is safe to send over an untrusted channel.
Encryption (E) — the algorithm plus key that turns plaintext into ciphertext; decryption (D) reverses it.
Key (K) — a secret value that selects one particular transformation out of the many the algorithm allows. The set of all possible keys is the key space; a k-bit key gives 2ᵏ keys.
Cipher — the algorithm itself (Caesar, DES, AES, RSA). A code is different: it replaces whole words or phrases using a codebook.
Cryptography designs ciphers, cryptanalysis attacks them, and cryptology is the combined field.
C = E(K, P) encryption
P = D(K, C) decryption
D(K, E(K, P)) = P correctness (symmetric case)
Asymmetric: C = E(PU_b, P) and P = D(PR_b, C)
The model of a cryptosystem (PU_b = receiver's public key, PR_b = receiver's private key)
Kerckhoffs's principle (Auguste Kerckhoffs, 1883) says a cryptosystem should stay secure even if everything about it except the key is public. Claude Shannon restated it as "the enemy knows the system". The opposite approach — hoping attackers never learn the algorithm — is called security through obscurity, and it fails because algorithms leak, get reverse-engineered or are sold.
Unconditional vs computational security
A cipher is unconditionally secure if the ciphertext reveals nothing about the plaintext however much computing power the attacker has — only the one-time pad achieves this. Practical ciphers (DES, AES, RSA) are computationally secure: breaking them costs more than the data is worth, or takes longer than the data's useful life.
02Security goals, services and attacks
Before choosing a cipher, decide what you are protecting and against whom. ITU-T recommendation X.800 (the OSI security architecture) lists the security services a system may need; textbooks summarise the core three as the CIA triad — confidentiality, integrity, availability.
Goal / service
Meaning
Typical mechanism
Confidentiality
Only authorised parties can read the data
Encryption (AES, RSA)
Integrity
Data has not been altered, inserted, deleted or replayed
Hash, MAC, digital signature
Availability
Authorised users get the service when they need it
Redundancy, DoS filtering, backups
Authentication
The peer (or the data's origin) is who it claims to be
Passwords, certificates, MACs, Kerberos
Non-repudiation
The sender cannot later deny sending, nor the receiver deny receiving
Digital signature with the sender's private key
Access control
Only permitted subjects may use a resource, and only in permitted ways
Access-control lists, capabilities, firewalls
Passive attacks
The attacker only observes; nothing is changed
Release of message contents (eavesdropping): reading an e-mail or a password in transit
Traffic analysis: even when contents are encrypted, learning who talks to whom, how often and how much
Very hard to detect, so the defence is prevention — mainly encryption, plus padding to hide traffic patterns
Active attacks
The attacker modifies the data stream or creates false data
Masquerade: pretending to be another entity, often with captured credentials
Replay: capturing a valid message and re-sending it later for an unauthorised effect
Modification of messages: altering, delaying or reordering a message ("pay 100" becomes "pay 1000")
Denial of service (DoS): preventing normal use, for example by flooding a server
Hard to prevent completely, so the aim is to detect them and recover
Traffic analysis is passive
Because the attacker never alters anything, traffic analysis is a passive attack — a favourite PSC distractor listed alongside masquerade, replay and modification. Non-repudiation is the service that stops a sender or receiver from denying a transmitted message.
03Classical substitution ciphers
A substitution cipher replaces each letter (or group of letters) with another symbol while keeping the letters in their original positions. Numbering the letters A = 0, B = 1, …, Z = 25 makes the rules easy to write as arithmetic modulo 26.
Caesar (shift) cipher: C = (P + k) mod 26 P = (C − k) mod 26
Example, k = 3: ATTACK AT DAWN → DWWDFN DW GDZQ
Vigenère cipher: Cᵢ = (Pᵢ + K₍ᵢ mod m₎) mod 26 (keyword of length m, repeated)
Caesar cipher — every letter shifts by the same amount k (Julius Caesar used 3). Only 25 useful keys exist, so an attacker simply tries them all: a brute-force attack.
Monoalphabetic cipher — the cipher alphabet is any permutation of the 26 letters, giving 26! ≈ 4 × 10²⁶ keys. Brute force is hopeless, yet the cipher falls to frequency analysis: the most common ciphertext letter probably stands for E, then T, A, O, I, N…
Playfair cipher (Charles Wheatstone, 1854; promoted by Lord Playfair) — encrypts pairs of letters (digraphs) with a 5 × 5 matrix built from a keyword, I and J sharing a cell. Working on pairs hides single-letter frequencies.
Vigenère cipher — a polyalphabetic cipher: a repeating keyword chooses a different Caesar shift for each position, so one plaintext letter encrypts differently in different places. It was broken in the 19th century (Babbage, Kasiski) by finding the key length from repeated fragments.
Vernam cipher and the one-time pad — XOR the plaintext with a key stream (Gilbert Vernam, 1917). If the key is truly random, as long as the message and never reused, the ciphertext reveals nothing: the one-time pad is the only cipher with perfect secrecy (proved by Shannon). The catch is distributing that much key.
Playfair rules
Build the matrix
Write the keyword's letters (dropping repeats), then the rest of the alphabet, row by row into a 5 × 5 grid; I and J share one cell.
Split into pairs
Break the plaintext into digraphs. If both letters of a pair are the same, insert a filler (usually X) between them; pad an odd last letter with X.
Same row
Replace each letter with the one to its right, wrapping from the last column back to the first.
Same column
Replace each letter with the one below it, wrapping from the bottom row back to the top.
Rectangle
Otherwise, each letter is replaced by the letter in its own row but in the other letter's column.
Row
Col 1
Col 2
Col 3
Col 4
Col 5
1
K
E
R
A
L
2
B
C
D
F
G
3
H
I/J
M
N
O
4
P
Q
S
T
U
5
V
W
X
Y
Z
Playfair matrix for the keyword KERALA (used in the worked example)
XOR in one line
Bitwise XOR (⊕) undoes itself: (P ⊕ K) ⊕ K = P. That is why one key stream both encrypts and decrypts in Vernam, in stream ciphers and in the OFB/CTR modes. It is also why reusing a pad is fatal: C₁ ⊕ C₂ = P₁ ⊕ P₂, because the key cancels out.
04Transposition and product ciphers
A transposition cipher keeps every letter but scrambles their order. Because the letters themselves are unchanged, the ciphertext has exactly the same letter frequencies as ordinary English — a quick way to recognise transposition.
Rail fence — write the message in a zigzag across n rails, then read rail by rail. MEET ME AT THE PARK on 2 rails: top rail MEMATEAK, bottom rail ETETHPR, so the ciphertext is MEMATEAKETETHPR.
Columnar transposition — write the message row by row under a keyword, then read the columns in the alphabetical order of the keyword's letters. The keyword (or the column order it implies) is the key.
Double transposition — apply columnar transposition twice; much harder to break than a single pass.
Keyword: Z E B R A
Rank: 5 3 2 4 1 (alphabetical order of the keyword letters)
M E E T M
E A F T E
R T H E P
A R T Y X (X = padding)
Read columns in rank order 1 (A), 2 (B), 3 (E), 4 (R), 5 (Z):
MEPX EFHT EATR TTEY MERA
Columnar transposition of MEET ME AFTER THE PARTY under keyword ZEBRA
A product cipher applies several simple steps — substitutions and transpositions — one after another, usually in repeated rounds. Each step alone is weak, but the combination is far stronger. Every modern block cipher is a product cipher: DES runs a Feistel network of S-box substitutions and bit permutations, and AES runs a substitution–permutation network.
Telling the families apart
Transposition: letters unchanged, only reordered — frequency counts match English. Monoalphabetic substitution: letters change but the shape of the frequency table survives. Polyalphabetic substitution (Vigenère, one-time pad) flattens the frequency table.
05Symmetric versus asymmetric encryption
In symmetric (secret-key, conventional, single-key) encryption the same key encrypts and decrypts, so sender and receiver must share it in advance. In asymmetric (public-key, two-key) encryption each user owns a key pair: a public key anyone may know and a private key only the owner holds. What one key of the pair does, only the other key can undo.
Feature
Symmetric (secret key)
Asymmetric (public key)
Keys
One shared secret key
Key pair: public + private
Speed
Very fast; suits bulk data (hardware AES runs at gigabytes per second)
Hundreds to thousands of times slower
Key length for ≈ 128-bit security
128 bits (AES-128)
RSA 3,072 bits or ECC 256 bits
Keys for n users
n(n − 1)/2, one per pair
2n, one pair per user
Key distribution
Hard: needs a secure channel or a key distribution centre
Easy: publish the public key (it must still be authenticated, e.g. by a certificate)
Services
Confidentiality; integrity through MACs
Confidentiality, digital signatures, key exchange
Mathematics
Substitution, permutation and XOR on bits
Number theory: factoring, discrete logarithms, elliptic curves
Examples
DES, 3DES, AES, IDEA, Blowfish, RC4, ChaCha20
RSA, Diffie–Hellman, ElGamal, DSA, ECC
Symmetric keys needed = n(n − 1) / 2
Asymmetric keys needed = 2n (n public + n private)
n = 10 → 45 shared keys vs 20 keys
n = 100 → 4,950 shared keys vs 200 keys
n = 1,000 → 499,500 shared keys vs 2,000 keys
Why public-key cryptography scales
Real systems use both. A hybrid scheme uses slow public-key cryptography only to agree on or transport a random session key, then encrypts the actual data with a fast symmetric cipher. TLS, SSH, PGP and S/MIME all work this way.
Which key for what?
To keep a message secret, encrypt with the receiver's public key — only the receiver's private key can decrypt it. To sign a message, the sender uses their own private key, and anyone verifies with the sender's public key.
06Block ciphers, stream ciphers and modes of operation
Block cipher
Encrypts a fixed-size block at a time: 64 bits (DES, 3DES, IDEA, Blowfish) or 128 bits (AES)
The same key and block always give the same output, so a mode of operation is needed for long messages
ECB and CBC need padding to a whole number of blocks
Examples: DES, 3DES, AES, IDEA, Blowfish, Twofish
Stream cipher
Generates a pseudo-random keystream from the key (and an IV) and XORs it with the data bit by bit or byte by byte
No padding; fast and simple, especially in hardware
Never reuse a key + IV: two messages under one keystream leak P₁ ⊕ P₂
Examples: RC4, ChaCha20, A5/1 (GSM); a block cipher in CFB, OFB or CTR mode also acts as a stream cipher
RC4 (Ron Rivest, 1987) was the most widely used stream cipher: the key (40 to 2,048 bits) shuffles a 256-byte state array, which then produces one keystream byte per step. It powered WEP and early SSL/TLS, but statistical biases in its output led RFC 7465 (2015) to prohibit RC4 in TLS. ChaCha20 (Daniel Bernstein) is its modern replacement.
Mode
How block i is encrypted
IV / nonce
Parallel?
Effect of a 1-bit ciphertext error
ECB — Electronic Codebook
Cᵢ = E(K, Pᵢ), each block alone
None
Encrypt and decrypt
Only that block is garbled
CBC — Cipher Block Chaining
Cᵢ = E(K, Pᵢ ⊕ Cᵢ₋₁), with C₀ = IV
Random, unpredictable IV
Decryption only
All of Pᵢ garbled and the same bit flipped in Pᵢ₊₁; then it recovers
CFB — Cipher Feedback
Cᵢ = Pᵢ ⊕ E(K, Cᵢ₋₁), in s-bit units
IV
Decryption only
That unit plus the next few, until the bad bits leave the shift register
OFB — Output Feedback
Oᵢ = E(K, Oᵢ₋₁) and Cᵢ = Pᵢ ⊕ Oᵢ
IV, never reused
Keystream can be precomputed; otherwise sequential
Only the same bit — no propagation
CTR — Counter
Cᵢ = Pᵢ ⊕ E(K, nonce ‖ counterᵢ)
Nonce, never reused
Encrypt and decrypt; random access to any block
Only the same bit — no propagation
Why ECB leaks patterns. ECB is deterministic block by block: identical plaintext blocks always give identical ciphertext blocks. Encrypt a bitmap image in ECB and its outline is still visible in the ciphertext; encrypt a table of salaries and equal salaries show up as equal ciphertext. CBC fixes this by XORing each block with the previous ciphertext block (and the first block with a random initialisation vector, IV), so repeats are hidden.
Remembering the five modes
ECB = each block alone; CBC = chain with the previous ciphertext; CFB = feed the previous ciphertext back into the cipher; OFB = feed the cipher's own output back (independent of the data); CTR = encrypt a counter. Modern protocols prefer authenticated modes such as GCM, which is CTR plus an authentication tag.
07Confusion, diffusion and cryptanalysis
In his 1949 paper Communication Theory of Secrecy Systems, Claude Shannon named two properties every strong cipher needs. Confusion makes the relationship between the key and the ciphertext as complex as possible, so each ciphertext bit depends on many key bits in a non-linear way — achieved by substitution (S-boxes). Diffusion spreads the influence of each plaintext bit over many ciphertext bits, dissolving statistical patterns — achieved by permutation and mixing.
Repeating rounds of confusion and diffusion produces the avalanche effect: flip a single bit of the plaintext or the key and about half of the ciphertext bits change. A cipher without a strong avalanche effect lets an attacker learn things by comparing outputs of similar inputs.
Attack type
What the attacker has
Example
Ciphertext-only
Only intercepted ciphertext (and the algorithm)
Frequency analysis of a monoalphabetic cipher
Known-plaintext
Some matching plaintext–ciphertext pairs
Knowing every message starts with a fixed header; linear cryptanalysis
Chosen-plaintext
Can have plaintexts of their choice encrypted
Feeding chosen inputs to an encryption device; differential cryptanalysis
Chosen-ciphertext
Can have chosen ciphertexts decrypted (but not the target)
Padding-oracle attacks on CBC; attacks on RSA padding
Brute force (exhaustive key search)
Ciphertext plus a way to recognise the right plaintext
Trying all 2⁵⁶ DES keys
Brute force tries every key; on average the right one turns up after searching half the key space. Key length therefore matters enormously, because each extra bit doubles the work.
Key size
Number of keys
Whole space at 10⁹ keys/s
Whole space at 10¹² keys/s
40 bits
2⁴⁰ ≈ 1.1 × 10¹²
≈ 18 minutes
≈ 1.1 seconds
56 bits (DES)
2⁵⁶ ≈ 7.2 × 10¹⁶
≈ 2.3 years
≈ 20 hours
128 bits (AES-128)
2¹²⁸ ≈ 3.4 × 10³⁸
≈ 1.1 × 10²² years
≈ 1.1 × 10¹⁹ years
Smarter attacks exploit structure instead of trying every key. Differential cryptanalysis (Biham and Shamir, 1990) studies how chosen input differences propagate through the rounds; linear cryptanalysis (Matsui, 1993) uses linear approximations over many known plaintexts; side-channel attacks measure the timing, power use or electromagnetic leakage of an implementation rather than attacking the mathematics.
08Hash functions, MACs and digital signatures
A cryptographic hash function H maps a message of any length to a short, fixed-length digest (message digest, fingerprint). It uses no key, so anyone can compute it. Change one bit of the message and the digest changes completely, which makes hashes the basic tool for integrity.
Pre-image resistance (one-way) — given a digest h, it is infeasible to find any message M with H(M) = h.
Second pre-image resistance (weak collision resistance) — given M₁, it is infeasible to find a different M₂ with H(M₂) = H(M₁).
Collision resistance (strong collision resistance) — it is infeasible to find any pair M₁ ≠ M₂ with the same digest. Because of the birthday paradox, an n-bit hash gives only about 2^(n/2) work against collisions.
Practical requirements: accepts input of any length, gives output of fixed length, and is fast to compute.
Hash
Designer / year
Digest size
Status
MD5
Ron Rivest, 1991 (RFC 1321)
128 bits
Broken — collisions found in seconds; use only as a non-security checksum
SHA-1
NSA / NIST, 1995 (FIPS 180-1)
160 bits
Broken — first public collision (SHAttered) in 2017
SHA-256 (SHA-2 family)
NSA / NIST, 2001
256 bits (family also has 224, 384, 512)
Secure; the most widely used today
SHA-3 (Keccak)
Bertoni, Daemen, Peeters, Van Assche; FIPS 202, 2015
224 to 512 bits
Secure; a different (sponge) design from SHA-2
A plain hash cannot stop an attacker who changes the message and recomputes the hash. A message authentication code (MAC) mixes in a shared secret key: tag = MAC(K, M). Only someone who knows K can produce a valid tag, so a MAC provides integrity and data-origin authentication. HMAC (RFC 2104, 1997) builds a MAC from any hash function.
HMAC(K, M) = H( (K⁺ ⊕ opad) ‖ H( (K⁺ ⊕ ipad) ‖ M ) )
K⁺ = the key padded to the hash's block size (64 bytes for SHA-256)
ipad = the byte 0x36 repeated opad = the byte 0x5C repeated ‖ = concatenation
A digital signature goes one step further. The sender hashes the message and transforms the digest with their private key; anyone can verify it with the sender's public key. Since only the sender holds that private key, a signature also gives non-repudiation — which a MAC cannot, because both parties share the MAC key and either could have produced the tag. RSA signatures are worked out in the RSA topic.
Tool
Key used
Integrity
Authenticates origin
Non-repudiation
Hash (e.g. SHA-256)
None
Only against accidental change
No
No
MAC / HMAC
Shared secret key
Yes
Yes
No
Digital signature
Private key signs, public key verifies
Yes
Yes
Yes
Worked examples
Try the problem first, then reveal the working one step at a time.
EX 1Caesar cipher: encrypt, then break by brute force
(a) Encrypt ATTACK AT DAWN with a Caesar shift of k = 3. (b) An intercepted Caesar ciphertext reads WKLV LV IXQ. Recover the plaintext without knowing the key.
EX 2Playfair encryption with keyword KERALA
Encrypt HIDE THE GOLD using the Playfair matrix for keyword KERALA (shown in the substitution-cipher section).
EX 3Vigenère with a repeating key
Encrypt HELLOWORLD with the Vigenère key KEY.
EX 4How many keys does an organisation need?
A housing board has 100 officers who must all be able to exchange confidential messages pairwise. How many keys are needed with (a) symmetric encryption and (b) public-key encryption? How many new keys does one new officer add in each case?
Practice session
Work each problem on paper first, then check. Marking one solved earns 10 XP.0/5 solved
Q1
Encrypt KERALA PSC EXAM with a columnar transposition under the keyword HOUSE (drop the spaces and pad the last row with X).
Q2
Encrypt MEET ME AT THE PARK with a rail fence cipher of depth 3.
Q3
A file of five 128-bit blocks P₁ … P₅ is encrypted with AES, and P₁ = P₄. (a) What can an eavesdropper notice in ECB mode that they cannot notice in CBC mode? (b) In CBC mode one bit of ciphertext block C₂ is flipped in transit. Which decrypted blocks are affected, and how?
Q4
An old export-grade cipher used 40-bit keys. A cracking rig tests 10⁹ keys per second. How long does it need in the worst case and on average? Repeat for a 56-bit DES key.
Q5
Two messages were encrypted with the same one-time pad (the key was reused): C₁ = 1100 1010 and C₂ = 0110 0011. The attacker also learns P₁ = 0101 1110. Find the pad K and the plaintext P₂, and explain why key reuse is fatal.
Exam traps
Traffic analysis is passive. It changes nothing, so it belongs with eavesdropping — not with masquerade, replay, modification and denial of service, which are all active.
Kerckhoffs's principle means only the key must be secret; the algorithm can be public. "Security through obscurity" is the opposite idea, not a restatement of it.
Counting keys: n users need n(n − 1)/2 symmetric keys but 2n asymmetric keys. Some books say "n key pairs" — 2n keys and n pairs are the same answer, so check what the question counts.
Hashing is not encryption — there is no key and no decryption. A MAC adds a shared key (integrity plus origin authentication) but no non-repudiation; only a digital signature gives non-repudiation.
Transposition keeps letter frequencies; monoalphabetic substitution changes the letters but keeps the frequency pattern; polyalphabetic ciphers flatten it.
Mode details: CBC decryption can run in parallel but CBC encryption cannot; CTR is parallel both ways; OFB and CTR do not propagate bit errors; only ECB leaks repeated blocks.
Quiz — KPSC style
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Cryptography basics: symmetric vs asymmetric · Question 1 of 12✓ 0 · ✗ 0
According to Kerckhoffs's principle, the security of a cryptosystem should depend on the secrecy of:
Past-paper questions on this topic
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.
Past papers · Question 1 of 14✓ 0 · ✗ 0
Modelled on QP 105/2024 · Higher Secondary School Teacher (Junior) Computer Science (8 Aug 2024), Q.90 (reworded)original paper (PDF)
Which of these is a passive attack rather than an active one?