Basics of Cryptography and Cybersecurity

Chapter 4
Cryptographic Foundations and Mathematics

Diploma in Cyber security
Basics of Cryptography and Cybersecurity   •   Diploma

Cryptographic Foundations and Mathematics

Introduction

Cryptography is the disciplined use of mathematical techniques to protect information and communications. It supports confidentiality, integrity, authentication, non-repudiation, and controlled access. Modern cryptography is not primarily about hiding messages through obscure procedures. It is about designing publicly understood algorithms whose security depends on carefully protected keys and well-supported computational assumptions.

A cybersecurity professional must therefore understand both the language of cryptography and the mathematical ideas that make cryptographic protection possible. This chapter introduces plaintext, ciphertext, keys, entropy, randomness, modular arithmetic, computational hardness, Kerckhoffs’s principle, and the practical limits of cryptography.

Learning Objectives

By the end of this chapter, you should be able to:

  • distinguish plaintext, ciphertext, encryption, decryption, and keys;
  • explain entropy and why secure randomness is essential;
  • perform basic modular-arithmetic calculations;
  • describe one-way functions, hard problems, and security parameters;
  • apply Kerckhoffs’s principle to system design;
  • identify what cryptography can and cannot protect;
  • evaluate cryptographic choices in a practical cybersecurity scenario.

1. The Cryptographic Model

A basic encryption system transforms readable information into an apparently unintelligible form. The readable information is plaintext, usually represented by the symbol m. Encryption applies an algorithm and a key to plaintext and produces ciphertext, represented by c. Decryption uses the appropriate key to recover the plaintext.

For a symmetric encryption system, the relationship is:

c = EncK(m)

and

m = DecK(c)

Here, Enc is the encryption algorithm, Dec is the decryption algorithm, K is the secret key, and the algorithms are assumed to be correctly implemented. Correctness requires that decryption reverses encryption for valid messages and keys:

DecK(EncK(m)) = m

This equation expresses correctness, not security. An encryption algorithm may correctly decrypt messages and still be insecure if an attacker can recover the key or infer the plaintext efficiently.

In symmetric cryptography, the same secret key, or closely related secret keys, is used for encryption and decryption. Examples include AES and ChaCha20. Symmetric algorithms are generally efficient and suitable for bulk data, but the communicating parties must obtain the shared secret securely.

In asymmetric cryptography, a key pair is used. The public key may be distributed openly, while the private key must remain secret. In a simplified encryption model, a sender encrypts using the recipient’s public key and the recipient decrypts using the private key. Public-key systems assist with key establishment and digital signatures but are usually slower than symmetric encryption.

Important Terminology

TermMeaning
PlaintextOriginal readable or usable information
CiphertextTransformed output of encryption
KeySecret or public value controlling a cryptographic operation
EncryptionTransformation from plaintext to ciphertext
DecryptionRecovery of plaintext from ciphertext
CipherAn encryption or decryption algorithm
CryptanalysisStudy of methods for defeating or evaluating cryptographic protection
Cryptographic primitiveFundamental mechanism such as a block cipher, hash function, or MAC
ProtocolOrdered rules governing cryptographic operations and communication

A complete cryptographic system includes more than an algorithm. It includes key generation, storage, distribution, use, rotation, revocation, error handling, and protection against implementation attacks. A mathematically strong cipher can be undermined by a leaked key, a reused nonce, weak random numbers, or an insecure protocol.

2. Security Services and Threats

Cryptography may provide several security services:

  • Confidentiality: preventing unauthorized disclosure.
  • Integrity: detecting unauthorized modification.
  • Authentication: establishing the identity or origin of a party or message.
  • Non-repudiation: providing evidence that supports attribution, usually through digital signatures and appropriate governance.
  • Freshness: helping detect replay of old messages.

These services are related but not identical. Encryption alone does not necessarily provide integrity. For example, an attacker might alter ciphertext bits without learning the plaintext. A secure modern design commonly uses authenticated encryption, which combines confidentiality and integrity under defined conditions.

A message authentication code (MAC) uses a shared secret to produce an authenticator. A receiver possessing the secret can verify that the message came from someone holding that secret and was not modified. A digital signature uses a private key to create a signature that can be verified with a public key. It supports public verification, although legal non-repudiation also depends on identity management, evidence, and applicable law.

3. Entropy and Information Uncertainty

Cryptography depends heavily on unpredictable values. Keys, initialization vectors, nonces, salts, session identifiers, and temporary secrets must often be generated with high-quality randomness.

In information theory, the entropy of a discrete random variable X is commonly defined as:

H(X) = −∑i=1n pi log₂(pi)

Here, pᵢ is the probability of outcome i, the sum covers all possible outcomes, and entropy is measured in bits when the logarithm is base 2. The formula applies to a specified probability distribution. It measures average uncertainty, not automatically the number of secure bits available against every attack.

For a uniform distribution over N equally likely outcomes:

H(X) = log₂(N)

For example, a uniformly selected six-digit decimal code has N = 1,000,000 possible values, so its ideal entropy is approximately:

H(X) = log₂(1,000,000) ≈ 19.93 bits

This is an ideal upper bound. If users choose predictable codes, or if an attacker knows that some codes are more likely, the effective security is lower.

Entropy, Min-Entropy, and Guessing

Average entropy does not always describe the most dangerous outcome. When the concern is the attacker’s best single guess, min-entropy is useful:

H_∞(X) = −log₂(maxi pi)

The largest probability determines min-entropy. A value may have reasonable average entropy while still having a highly probable first guess.

Entropy is also not identical to randomness. A source can have a large theoretical space but produce predictable outputs. A password selected by a user from a large character set may have less practical security than a shorter value generated uniformly by a cryptographic random generator.

Randomness Sources

A true random number generator (TRNG) obtains randomness from physical processes, such as electronic noise. A cryptographically secure pseudorandom number generator (CSPRNG) expands a short, secret internal state into a longer sequence that should be computationally unpredictable, provided its seed and implementation are secure.

A CSPRNG must be distinguished from an ordinary pseudorandom generator used for simulation or games. Statistical appearance alone does not establish cryptographic security. A sequence can pass simple frequency tests and still be predictable.

Best practices include:

  1. use the operating system’s approved CSPRNG;
  2. do not seed cryptographic generators with timestamps or user identifiers alone;
  3. protect generator state and seed material;
  4. avoid manually inventing random-number algorithms;
  5. obtain independent review for security-critical randomness.

4. Modular Arithmetic

Modular arithmetic is arithmetic with remainders. We write:

a ≡ b (mod n)

when a and b have the same remainder after division by positive integer n. Equivalently, n divides a − b.

For example:

29 ≡ 5 (mod 12)

because 29 and 5 both leave remainder 5 when divided by 12.

The basic operations are performed as follows:

(a + b) mod n = ((a mod n) + (b mod n)) mod n
(a × b) mod n = ((a mod n) × (b mod n)) mod n

These rules allow systems to work with bounded values and are central to many cryptographic constructions.

Modular Inverses

The modular inverse of a modulo n is a value a⁻¹ satisfying:

a × a⁻¹ ≡ 1 (mod n)

An inverse exists if and only if gcd(a,n) = 1, meaning that a and n share no common factor other than 1.

For example, the inverse of 3 modulo 7 is 5 because:

3 × 5 = 15 ≡ 1 (mod 7)

The extended Euclidean algorithm efficiently finds such inverses. Modular inverses are used in public-key algorithms and some algebraic constructions.

Worked Example: Modular Exponentiation

Calculate 5³ mod 13:

5³ = 125

Dividing 125 by 13 gives remainder 8, so:

5³ ≡ 8 (mod 13)

In real cryptographic systems, exponents may be hundreds or thousands of bits long. Algorithms such as repeated squaring calculate modular powers efficiently without first constructing the full enormous integer.

Prime Numbers and Finite Structures

A prime number has exactly two positive divisors: 1 and itself. Prime numbers are important because arithmetic modulo a prime creates a field, in which every non-zero element has a multiplicative inverse. Many cryptographic systems use finite groups or fields, but the existence of modular arithmetic alone does not make a system secure. Security depends on the selected structure, parameters, algorithm, and implementation.

5. Computational Hardness

Cryptographic security often relies on problems that are easy to perform in one direction but difficult to reverse without secret information. “Difficult” normally means computationally infeasible for the attacker’s resources and time, not mathematically impossible.

A one-way function is easy to compute but computationally difficult to invert for most inputs. A trapdoor one-way function is difficult to invert generally but easy to invert when a secret trapdoor is known. Public-key cryptography uses this type of asymmetry in various forms.

Examples of hardness assumptions include:

  • factoring a large composite integer;
  • computing a discrete logarithm in a suitable group;
  • solving certain lattice-based problems;
  • finding a hash collision under a secure hash-function model.

These assumptions must be stated carefully. A problem may be hard for known classical algorithms but become easier with a future algorithm, better hardware, poor parameter choices, or implementation leakage.

Work Factor and Security Parameters

The work factor is the computational effort an attacker must expend. A security parameter controls the size or strength of cryptographic values. Larger parameters often increase attack cost, but they may also increase processing time, memory use, bandwidth, or power consumption.

Security estimates are probabilistic and time-dependent. A claim such as “128-bit security” generally means that the best relevant generic attack is expected to require on the order of 2¹²⁸ operations under specified assumptions. It does not mean that every component of the system automatically has exactly 128 bits of protection.

Hash Functions

A cryptographic hash function maps an input of arbitrary practical length to a fixed-length digest:

h = H(m)

Important properties include preimage resistance, second-preimage resistance, and collision resistance. A collision occurs when two different messages produce the same digest. Because a fixed-length output has finitely many values while inputs are effectively much larger, collisions must exist mathematically. Security requires that finding a useful collision be computationally infeasible.

For an ideal n-bit hash function, a generic collision search has an approximate birthday-bound work factor of 2ⁿᐟ², not 2ⁿ. This distinction is important when selecting digest sizes.

6. Kerckhoffs’s Principle

Kerckhoffs’s principle states that a cryptosystem should remain secure even if everything about the system, except the key, is public. The algorithm, protocol design, and implementation documentation should not need to remain secret for the system to resist attack.

This principle does not require publishing private keys, passwords, or sensitive operational information. It means that secrecy of the mechanism should not be the primary security barrier. Public algorithms can receive independent analysis, testing, and criticism. Secret algorithms receive less scrutiny and may conceal serious weaknesses until attackers discover them.

Kerckhoffs’s principle is often summarized as “security through key secrecy, not algorithm secrecy.” It is closely related to open design and should not be confused with careless disclosure of credentials or source code containing secrets.

A practical design should assume that an attacker may know:

  • the algorithm and protocol;
  • message formats and public parameters;
  • software versions and network behavior;
  • much of the implementation logic.

The attacker should still be unable to defeat the system without the protected key or another privileged capability.

7. Key Management and the Human Element

The key is only one part of a key-management lifecycle:

  1. generation;
  2. registration and association with an identity;
  3. distribution or establishment;
  4. protected storage;
  5. controlled use;
  6. rotation and renewal;
  7. backup and recovery where appropriate;
  8. revocation;
  9. secure destruction.

Poor key management is among the most common causes of cryptographic failure. Examples include hard-coded keys in applications, shared administrator passwords, unprotected private keys, excessive key reuse, and failure to revoke compromised certificates.

A nonce is a value intended to be used once in a defined context. A nonce need not always be secret, but its uniqueness requirement must be respected. Reusing a nonce with some encryption modes can reveal relationships between plaintexts or even compromise confidentiality. Salts, by contrast, are commonly public random values added to password-derived computations to prevent identical passwords from producing identical stored values and to frustrate precomputed tables.

Passwords should not normally be encrypted for storage. They should be processed using a password-hashing or password-based key-derivation function with a unique salt and deliberately expensive parameters. The exact choice must follow current standards and organizational requirements.

8. Applied Case: Protecting a Small Online Retailer

The following is an illustrative case designed for learning.

Background

A small online retailer stores customer accounts, order information, and payment-related tokens. Its developers propose encrypting the customer database with one AES key embedded in the application source code. They also use a general-purpose random function to create password-reset tokens.

Problem

The proposed design has two serious weaknesses. Anyone who obtains the source code or compromises the application may recover the database key. The ordinary random function may produce predictable reset tokens, allowing account takeover.

Analysis

The encryption algorithm may be strong, but Kerckhoffs’s principle requires the design to remain secure even when the algorithm and code structure are known. The key must therefore be stored and used through a controlled key-management mechanism, such as a dedicated secrets manager or hardware-backed key service. Access should be limited, logged, and periodically reviewed.

Password-reset tokens require unpredictable generation, sufficient length, expiration, single-use enforcement, and protection against leakage through logs or URLs. Database encryption also does not prevent a compromised application from reading data after legitimate decryption. Additional controls are required for authorization, monitoring, input validation, and endpoint security.

Approach and Solution

The retailer should use a vetted authenticated-encryption mode through a maintained library, generate nonces according to the mode’s requirements, and protect keys outside the source repository. Passwords should be processed with a modern password-derivation function and unique salts. Reset tokens should come from a CSPRNG and be stored in a form that limits the impact of database compromise. Access should be segmented so that application components receive only the permissions required for their tasks.

Outcome

The redesigned system reduces the risk of database disclosure and token prediction, although it does not eliminate all risk. Compromise of an application account, an administrator, or an endpoint could still expose information. The case demonstrates that cryptography must be integrated with identity, access control, software security, monitoring, and incident response.

Learning Points

  • Strong algorithms cannot compensate for exposed keys.
  • Randomness must be appropriate to the threat model.
  • Encryption does not replace authorization or secure coding.
  • Protocol and lifecycle design are as important as mathematical primitives.

9. Limitations, Ethics, and Governance

Cryptography protects data only within its scope. It cannot determine whether a user is trustworthy, whether data was accurate before encryption, or whether an authorized process will misuse decrypted information. It cannot prevent phishing, insecure endpoints, malicious insiders, ransomware, or social engineering by itself.

Endpoint compromise is especially important. If malware captures plaintext before encryption or after decryption, a secure cipher cannot help. Similarly, encrypted traffic can still reveal metadata such as timing, volume, destination, and communication patterns.

Organizations must also consider lawful access requirements, data-protection obligations, retention rules, export controls where applicable, and responsible handling of cryptographic keys. Security teams should avoid creating unauthorized access mechanisms or “back doors,” because such mechanisms can become targets and weaken protection for legitimate users.

Contemporary Developments

Quantum computing motivates migration planning because sufficiently capable quantum computers could threaten some widely used public-key assumptions. Post-quantum cryptography develops algorithms intended to resist known quantum attack strategies. Symmetric cryptography and hash functions are affected differently, and organizations should follow current standards rather than independently changing key sizes.

Cryptographic agility—the ability to replace algorithms, parameters, and certificates without redesigning an entire system—is increasingly important. Inventorying cryptographic use, removing obsolete algorithms, and planning transitions are practical responsibilities for cybersecurity professionals.

Artificial intelligence may assist with code review, anomaly detection, and cryptographic inventory, but it does not prove security. AI-generated cryptographic code must be reviewed, tested, and validated against authoritative standards. Security decisions remain subject to threat modeling and expert oversight.

Best-Practice Checklist

  • Use standardized, peer-reviewed algorithms and maintained libraries.
  • Protect keys separately from the data they encrypt.
  • Use a CSPRNG for security-sensitive values.
  • Define nonce, salt, key-length, and rotation requirements explicitly.
  • Prefer authenticated encryption for messages requiring confidentiality and integrity.
  • Use secure password-derivation functions rather than reversible encryption for passwords.
  • Document assumptions, trust boundaries, and failure handling.
  • Plan certificate and key revocation before deployment.
  • Monitor for obsolete algorithms and cryptographic misuse.
  • Treat cryptography as one layer in a broader defense-in-depth architecture.

Chapter Summary

Cryptography transforms information and authenticates communications through algorithms, keys, and protocols. Plaintext becomes ciphertext through encryption, and correctness requires valid decryption to recover the original message. Entropy measures uncertainty, while cryptographic security additionally requires unpredictable generation and sound implementation. Modular arithmetic provides the algebraic foundation for many cryptographic constructions, including modular inverses and exponentiation. Computational hardness explains why some operations are easy to perform but difficult to reverse without secret information.

Kerckhoffs’s principle requires security to depend on protected keys rather than secret algorithms. In practice, key management, randomness, nonce handling, protocol design, software quality, and endpoint security are as important as the selected cipher. Cryptography cannot solve every cybersecurity problem: it does not prevent compromised endpoints, misuse by authorized users, metadata leakage, or poor governance. Professional practice therefore combines cryptographic mechanisms with identity management, secure development, monitoring, legal compliance, and lifecycle planning.

Key Terms

Plaintext: Original readable or usable information before encryption.

Ciphertext: Transformed information produced by encryption.

Key: A value controlling a cryptographic operation.

Symmetric cryptography: Cryptography using a shared secret key.

Asymmetric cryptography: Cryptography using related public and private keys.

Entropy: A measure of uncertainty in a probability distribution.

Min-entropy: Uncertainty determined by the probability of the most likely outcome.

CSPRNG: A cryptographically secure pseudorandom number generator.

Modular arithmetic: Arithmetic based on remainders under a modulus.

Modular inverse: A value that multiplies with another value to produce 1 modulo a specified modulus.

One-way function: A function intended to be easy to compute and difficult to invert.

Computational hardness: Practical difficulty of solving a problem with available resources.

Hash function: A function mapping input data to a fixed-length digest.

Collision: Two distinct inputs producing the same hash output.

Nonce: A value intended for one-time use within a defined cryptographic context.

Salt: An additional value used with password processing to resist precomputation and equal-output patterns.

Kerckhoffs’s principle: The principle that a system should remain secure when its design is public except for secret keys.

Key management: The generation, protection, distribution, use, rotation, revocation, and destruction of keys.

Cryptographic agility: The capability to replace cryptographic algorithms or parameters with limited disruption.

Review Questions

Short Answer Questions

  1. What is the difference between plaintext and ciphertext?
  2. Why is entropy important when generating cryptographic keys?
  3. State the condition under which a modular inverse of a modulo n exists.
  4. What does Kerckhoffs’s principle require?
  5. Why does encryption alone not necessarily provide integrity?

Long Answer Questions

  1. Explain the roles of encryption algorithms, keys, and protocols in a complete cryptographic system.
  2. Describe entropy, min-entropy, and the difference between theoretical and effective randomness.
  3. Explain modular arithmetic, modular inverses, and their relevance to cryptography.
  4. Discuss computational hardness and why security estimates depend on assumptions and resources.
  5. Explain the major stages of the cryptographic key-management lifecycle.

Analytical / Application Questions

  1. A developer uses a timestamp as the seed for password-reset tokens. Analyze the threat and recommend a safer design.
  2. An organization encrypts a database but stores the encryption key in the same database. Evaluate the security model and propose controls.
  3. A system uses a secure cipher but reuses a nonce in a mode that requires nonce uniqueness. Explain why this may be dangerous and identify the broader lesson for protocol design.

Multiple Choice Questions with Answers

Question 1

What is the primary purpose of a cryptographic key?

A. To determine or control a cryptographic operation

B. To increase the size of every plaintext message

C. To replace the need for authentication

D. To guarantee that endpoints cannot be compromised

Correct Answer: A. To determine or control a cryptographic operation

Question 2

What is the ideal entropy of a uniformly selected value from 1,024 possible outcomes?

A. 8 bits

B. 10 bits

C. 32 bits

D. 1,024 bits

Correct Answer: B. 10 bits

Question 3

Which condition is required for a modular inverse of a modulo n to exist?

A. a must be larger than n

B. n must be even

C. gcd(a,n) must equal 1

D. a must be a prime number

Correct Answer: C. gcd(a,n) must equal 1

Question 4

According to Kerckhoffs’s principle, what should remain secret?

A. The encryption algorithm

B. The public protocol documentation

C. The key

D. The existence of ciphertext

Correct Answer: C. The key

Question 5

What is the main role of a cryptographically secure pseudorandom number generator?

A. To produce values that are computationally unpredictable

B. To compress plaintext without information loss

C. To authenticate users without credentials

D. To guarantee perfect physical randomness

Correct Answer: A. To produce values that are computationally unpredictable

Question 6

Calculate 29 mod 12.

A. 1

B. 3

C. 5

D. 7

Correct Answer: C. 5

Question 7

Which statement about a cryptographic hash function is correct?

A. It normally maps arbitrary input to a fixed-length digest

B. It always allows the original message to be recovered

C. It requires the same secret key as symmetric encryption

D. It prevents all possible collisions mathematically

Correct Answer: A. It normally maps arbitrary input to a fixed-length digest

Question 8

Why should passwords generally be processed with a password-derivation function rather than encrypted for storage?

A. Password derivation is intended to make verification costly and resist recovery of the original password

B. Encryption cannot operate on text strings

C. Derived passwords are always shorter than plaintext passwords

D. Password derivation eliminates the need for salts

Correct Answer: A. Password derivation is intended to make verification costly and resist recovery of the original password

Question 9

What is a key limitation of cryptography when an endpoint is infected with malware?

A. The malware may capture plaintext before encryption or after decryption

B. The encryption algorithm automatically changes its key

C. Ciphertext becomes mathematically impossible to transmit

D. Modular arithmetic stops functioning

Correct Answer: A. The malware may capture plaintext before encryption or after decryption

Question 10

For an ideal hash function with an n-bit output, the approximate generic collision work factor is:

A. 2ⁿ operations

B. 2ⁿᐟ² operations

C. n² operations in every case

D. log₂(n) operations

Correct Answer: B. 2ⁿᐟ² operations

Basics of Cryptography and Cybersecurity
Chapter 4 of 14