CYS 401 · Chapter 5

The Science of
Cryptography

Cipher Methods, Algorithms, Attacks, Hashing, and Secure Communication Protocols

Basic Concepts Classical Ciphers Symmetric vs Asymmetric Hash Functions Cryptanalysis Kerckhoffs's Principle
scroll ↓
01

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.

Plaintext
The original, readable message before any encryption is applied.
Ciphertext
The scrambled, unreadable message produced after encryption.
Cipher
The algorithm used to transform plaintext into ciphertext (and back).
Key
The secret information used by the cipher — known only to sender/receiver.
Encryption (Encipher)
Converting plaintext → ciphertext. Allows two parties to communicate over an insecure channel.
Decryption (Decipher)
Converting ciphertext → plaintext. Recovers the original message.
Cryptography
Study of encryption principles/methods. Can protect Confidentiality and Integrity — but NOT Availability.
Cryptanalysis
The process of obtaining the original message from ciphertext without the key. Also called "codebreaking."
Cryptology
The overall field combining both Cryptography and Cryptanalysis.
📄 Plaintext
🔐 Encrypt
+ Key
📡 Insecure Channel
(Ciphertext)
🔓 Decrypt
+ Key
📄 Plaintext

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.

02

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.

✅ Made Public

The encryption/decryption algorithm — anyone (including attackers) can know it.

🔒 Kept Secret

Only the key is kept secret. The resistance of the cipher relies entirely on key secrecy.

📘 Real-World Example

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.

03

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
🌳 Cipher Classification Tree (from slides)
Ciphers ├── Symmetric │ ├── Classical │ │ ├── Substitution │ │ ├── Transposition │ │ └── Product │ └── Modern │ ├── Block Cipher │ └── Stream Cipher ├── Asymmetric └── Hash Functions
04

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

📘 Example from Slides (n = 14)
TypeText
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.

✨ Generated Example

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.

📘 Example from Slides
FieldValue
PlaintextGEEKSFORGEEKS
KeywordAYUSH (repeated → AYUSHAYUSHAYU)
CiphertextGCYCZFMLYLEIM

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.

✨ Generated Example

Plaintext: HELLO → rearranged by key pattern → Ciphertext: LLEHO. Frequency analysis won't help because letter frequencies are preserved.

05

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
Plaintext
Encrypt
🗝️ Shared Key
Decrypt
🗝️ Shared Key
Plaintext

🔑 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)
Key Rule

Encrypt with receiver's-public-key-→-decrypt-with-receiver's private key. Sign with sender's-private-key-→-verify-with-sender's public key.

FeatureSymmetricAsymmetric
Keys1 shared secret key2 keys: public + private
Speed~30,000× fasterMuch slower
Key DistributionDifficult / ProblemEasy (public key is public)
Use CasesBulk data encryptionKey exchange, digital signatures
Exam TrickProblem with symmetric = secure key distribution (from past exam)
🎓 Past Exam Question

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 ✅

🎓 Past Exam Question

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 ✅

06

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.

VersionYearDigest SizeStatus
SHA-11993160 bits⚠️ Vulnerable to collision attacks — avoid
SHA-22002SHA-256 or SHA-512✅ More secure than SHA-1
SHA-32015224, 256, 384, or 512 bits✅ Latest standard by NIST

📋 MD — Message Digest

VersionYearOutputNotes
MD21989128 bitsVulnerable without checksum
MD41990128 bitsFast but subject to many attacks
MD51991128 bitsBased 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.

07

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 TypeWhat the Attacker KnowsGoalDifficulty
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 SizePossible KeysTime @ 1 dec/μsTime @ 10⁶ dec/μs
32 bits4.3 × 10⁹35.8 minutes2.15 milliseconds
56 bits (DES)7.2 × 10¹⁶1,142 years10.01 hours ⚠️ Broken
128 bits (AES)3.4 × 10³⁸5.4 × 10²⁴ years5.4 × 10¹⁸ years ✅
168 bits (3DES)3.7 × 10⁵⁰5.9 × 10³⁶ years5.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.

✨ Generated Example

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.

08

Encryption vs Digital Signatures

🔐 Encryption (Confidentiality)

1

Sender encrypts

Using the receiver's public key

2

Receiver decrypts

Using their own private key

✍️ Digital Signature (Authentication)

1

Signer signs

Using their own private key

2

Anyone verifies

Using the sender's public key

🎓 Past Exam Question

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.

09

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.

🎓 From Past Exam

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.

10

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).

11

Quick Reference — Everything at a Glance

📌 Chapter 5 Master Cheat Sheet
TopicKey Point
Cryptography protectsConfidentiality + Integrity ONLY (not Availability)
Kerckhoffs's PrincipleAlgorithm = public; Key = secret
Symmetric1 shared key; fast (~30,000× faster); key distribution = problem
AsymmetricPublic + private keys; slower; solves key distribution
Encrypt for privacyUse receiver's PUBLIC key
Sign (digital signature)Use sender's PRIVATE key
Verify signatureUse sender's PUBLIC key
Caesar CipherE(x) = (x+n) mod 26; shift cipher; breakable by frequency analysis
Vigenère CipherPolyalphabetic substitution; keyword repeated; resists frequency analysis
One-Time PadUnbreakable; key = random, length of message, never reused
Hash = One-WayCannot reverse; fixed-length output; used for passwords + integrity
SHA-1160 bits; vulnerable to collision attacks — avoid
SHA-2/3SHA-256/512; current standard
Collision AttackTwo different inputs → same hash → loss of integrity
MACHash + secret key = proves integrity AND authenticity
Ciphertext Only AttackHardest; attacker has only ciphertext
Chosen Ciphertext AttackEasiest for attacker; has decryption oracle
DiffusionSpreads one plaintext character influence over many ciphertext chars
ConfusionConceals plaintext-ciphertext relationship; uses S-boxes
Brute ForceTry all keys; 128-bit AES = effectively unbreakable
Frequency AnalysisBreaks substitution ciphers using letter frequency patterns