Basic Concepts of Cryptography
Cryptography is the science of protecting information by transforming it. Plaintext is the readable message and ciphertext is the unreadable form. Encryption converts plaintext to ciphertext and decryption reverses it, using a key. A cipher is the algorithm. The security of a good cipher rests on the secrecy of the key and not of the algorithm (Kerckhoffs' principle). Classical techniques are substitution (replace symbols, as in the Caesar cipher, which shifts each letter by a fixed number) and transposition (rearrange the symbols). Modern ciphers combine substitution and transposition in many rounds, using the ideas of confusion (hide the link between key and ciphertext) and diffusion (spread the effect of one plaintext bit over many ciphertext bits).
Symmetric Encryption
In symmetric (secret-key) encryption the same key encrypts and decrypts, so the sender and receiver must share the key safely. It is fast and suits bulk data. Types are block ciphers (process fixed-size blocks) and stream ciphers (process bit by bit, such as RC4 or ChaCha20). A block cipher needs a mode of operation: ECB (each block alone; weak because equal blocks give equal ciphertext), CBC (each block is combined with the previous ciphertext using an initial vector), CTR (turns the cipher into a stream cipher) and GCM (adds authentication).
DES
The Data Encryption Standard (adopted in 1977) uses a 64-bit block and a 56-bit effective key (64 bits including parity), in 16 rounds of a Feistel network. Its short key made it breakable: in 1998 a special machine found a DES key in about 56 hours. Triple DES (3DES) applies DES three times and is now being retired.
AES
The Advanced Encryption Standard (Rijndael, chosen in 2001) uses a 128-bit block and a key of 128, 192 or 256 bits, with 10, 12 or 14 rounds. Each round has four steps on a 4 × 4 byte state: SubBytes (substitution with an S-box), ShiftRows (rotate rows), MixColumns (mix the bytes of each column) and AddRoundKey (XOR with the round key). It is secure, fast in software and hardware, and is today's standard for symmetric encryption.
Definition: Symmetric encryption. Encryption in which the same secret key is used to encrypt and decrypt data, so that both parties must hold the key and keep it secret.
Table 1.4: DES and AES
| Feature | DES | AES |
|---|---|---|
| Block size | 64 bits | 128 bits |
| Key size | 56 bits (effective) | 128, 192 or 256 bits |
| Rounds | 16 (Feistel) | 10, 12 or 14 (substitution-permutation) |
| Status | Broken, obsolete | Current standard |
Example 1.4: Brute-force time for DES and AES
Problem: An attacker tests one billion keys per second against DES (2⁵⁶ keys). Find the time to try all keys. Then find the time for AES-128 (2¹²⁸ keys) if the attacker could test 10¹² keys per second.
Solution:
- 2⁵⁶ = 7.2 × 10¹⁶ keys; time = 7.2 × 10¹⁶ / 10⁹ = 7.2 × 10⁷ seconds, which is 834 days, about 2.3 years (the average to find the key is half of this).
- 2¹²⁸ = 3.4 × 10³⁸ keys; time = 3.4 × 10³⁸ / 10¹² = 3.4 × 10²⁶ seconds.
- In years: 3.4 × 10²⁶ / 3.15 × 10⁷ = about 1.1 × 10¹⁹ years.
Result: DES falls to a single fast machine (and to much faster hardware); AES-128 would need about 10¹⁹ years, far longer than the age of the universe.
rate = 1e9
t56 = 2 ** 56 / rate
print("DES days:", round(t56 / 86400), "| years:",
round(t56 / 31536000, 2))
t128 = 2 ** 128 / 1e12
print("AES-128 years: %.2e" % (t128 / 31536000))
Output
DES days: 834 | years: 2.28
AES-128 years: 1.08e+19
Common mistakes
- Using ECB mode for data that has repeated patterns.
- Sending the secret key over the same insecure channel as the data.
- Choosing DES or a short key because it is fast.
- Inventing a private cipher instead of using a tested standard.
Key takeaways
- Symmetric: one shared key; fast; key distribution is the problem.
- DES: 64-bit block, 56-bit key, 16 rounds, obsolete.
- AES: 128-bit block, 128, 192 or 256-bit key, 10 to 14 rounds.
- Prefer CBC, CTR or GCM, not ECB.
Practice questions
- State the block size and key size of AES.
- Why is DES insecure today?
- What is the main problem of symmetric encryption?
Answers to the practice questions
- 128-bit block; 128, 192 or 256-bit key.
- Its 56-bit key can be searched by brute force in a short time.
- Sharing the secret key safely.
Sources
- Official BCA syllabus Computer Security, course code 25BCA406DS02, Unit I
