MTH381Semester 8 • 3 CreditsElective Subjects

Number Theory And Cryptography

This course covers number theory concepts including division algorithms, modular arithmetic, primes, GCD/LCM, and linear congruences, together with cryptography topics such as classical ciphers, public-key cryptography (Diffie-Hellman, RSA, ElGamal), and cryptographic protocols including hash functions, MACs, and digital signatures.

6 Units • Notes • Model Answers • MCQs
Select Course Unit (6 Units)
Active: Unit 1
Unit 1:Number Theory-I
30 mins•High-Yield Unit Guide

Number Theory-I

Unit 1 Exam Focus & Core Takeaways

Review the core definitions, standard architectures, and syntax patterns below. Pay special attention to sections highlighted with bullet points for your mid-term and end-term subjective questions.

Unit 1: Number Theory-I

1. The Integers and Divisibility

Number theory forms the mathematical cornerstone of modern cryptography, public-key encryption, and hashing algorithms. The domain of study is the set of integers Z={...,−2,−1,0,1,2,...}\mathbb{Z} = \{..., -2, -1, 0, 1, 2, ...\}.

1.1 Definition of Divisibility

Let a,b∈Za, b \in \mathbb{Z} with a≠0a \neq 0. We say that aa divides bb (written as a∣ba \mid b) if there exists an integer c∈Zc \in \mathbb{Z} such that:
b=a⋅cb = a \cdot c

  • If aa divides bb, then aa is called a factor or divisor of bb, and bb is called a multiple of aa.
  • If aa does not divide bb, we write a∤ba \nmid b.
  • Example: 3∣123 \mid 12 because 12=3×412 = 3 \times 4. Conversely, 5∤125 \nmid 12 because no integer cc satisfies 12=5c12 = 5c.

1.2 Fundamental Properties of Divisibility

For all integers a,b,c∈Za, b, c \in \mathbb{Z}:

Theorem / PropertyFormal StatementMathematical Consequence
Reflexivitya∣aa \mid a for all a≠0a \neq 0.Any non-zero integer divides itself (a=a⋅1a = a \cdot 1).
TransitivityIf a∣ba \mid b and b∣cb \mid c, then a∣ca \mid c.Divisibility chains preserve factors.
Linearity (Linear Combinations)If a∣ba \mid b and a∣ca \mid c, then a∣(mb+nc)a \mid (mb + nc) for any integers m,n∈Zm, n \in \mathbb{Z}.If aa divides two numbers, it divides any integer linear combination of them.
Multiplication PropertyIf a∣ba \mid b, then a∣bca \mid bc for any integer cc.Multiples inherit divisors.
Zero Divisibilitya∣0a \mid 0 for every non-zero integer aa.0=a⋅00 = a \cdot 0; zero is divisible by every non-zero integer.
BoundednessIf a∣ba \mid b and b≠0b \neq 0, then $a
AntisymmetryIf a∣ba \mid b and b∣ab \mid a, then a=±ba = \pm b.Mutual divisors in Z\mathbb{Z} differ at most by sign.

2. The Division Algorithm

Despite its historical name, the Division Algorithm is a foundational theorem that guarantees the existence and uniqueness of quotients and remainders.

2.1 Formal Statement

Let a∈Za \in \mathbb{Z} (the dividend) and d∈Z+d \in \mathbb{Z}^+ (a positive integer divisor). Then there exist unique integers qq (the quotient) and rr (the remainder) such that:

a=d⋅q+rwhere0≤r<da = d \cdot q + r \quad \text{where} \quad 0 \le r < d

  • q=⌊a/d⌋=adiv⁡dq = \lfloor a / d \rfloor = a \operatorname{div} d
  • r=a−d⋅q=a mod dr = a - d \cdot q = a \bmod d
CODE
Dividend (a)  =  Divisor (d) * Quotient (q)  +  Remainder (r)
                 [-------------------------]    [-----------]
                       Multiple of d             0 <= r < d

2.2 The Strict Constraint on the Remainder

The remainder rr must strictly satisfy 0≤r<d0 \le r < d. It can never be negative, and it must be strictly less than the divisor.

2.3 Division with Negative Dividends

When aa is negative, careful application of 0≤r<d0 \le r < d is mandatory:

  • Example 1: Divide a=−23a = -23 by d=5d = 5.
    −23=5⋅(−5)+2-23 = 5 \cdot (-5) + 2
    Here, q=−5q = -5 and r=2r = 2. Note that writing −23=5⋅(−4)−3-23 = 5 \cdot (-4) - 3 is mathematically invalid under the Division Algorithm because r=−3<0r = -3 < 0.
  • Example 2: Divide a=−11a = -11 by d=4d = 4.
    −11=4⋅(−3)+1  ⟹  q=−3,r=1-11 = 4 \cdot (-3) + 1 \implies q = -3, r = 1

3. Modular Arithmetic and Congruence

Modular arithmetic studies the arithmetic of remainders, forming the bedrock of cryptographic ciphers like RSA and Diffie-Hellman.

3.1 Definition of Congruence

Let m∈Z+m \in \mathbb{Z}^+ be a positive integer called the modulus. Two integers aa and bb are said to be congruent modulo mm (written a≡b(modm)a \equiv b \pmod m) if mm divides their difference:

a≡b(modm)  ⟺  m∣(a−b)a \equiv b \pmod m \iff m \mid (a - b)

Equivalent Characterization:
a≡b(modm)a \equiv b \pmod m if and only if aa and bb leave the exact same remainder when divided by mm:
a mod m=b mod ma \bmod m = b \bmod m

Examples:

  • 17≡5(mod6)17 \equiv 5 \pmod 6 because 17−5=1217 - 5 = 12, and 6∣126 \mid 12.
  • 28≡−2(mod10)28 \equiv -2 \pmod{10} because 28−(−2)=3028 - (-2) = 30, and 10∣3010 \mid 30.

3.2 Equivalence Relation and Residue Classes

Congruence modulo mm is an equivalence relation satisfying:

  1. Reflexive: a≡a(modm)a \equiv a \pmod m since m∣0m \mid 0.
  2. Symmetric: If a≡b(modm)a \equiv b \pmod m, then b≡a(modm)b \equiv a \pmod m.
  3. Transitive: If a≡b(modm)a \equiv b \pmod m and b≡c(modm)b \equiv c \pmod m, then a≡c(modm)a \equiv c \pmod m.

It partitions Z\mathbb{Z} into exactly mm disjoint residue classes modulo mm:
Zm={[0],[1],[2],...,[m−1]}\mathbb{Z}_m = \{[0], [1], [2], ..., [m - 1]\}
Where each class [r]={km+r∣k∈Z}[r] = \{km + r \mid k \in \mathbb{Z}\} represents all integers leaving remainder rr when divided by mm.

3.3 Algebraic Compatibility with Addition and Multiplication

If a≡b(modm)a \equiv b \pmod m and c≡d(modm)c \equiv d \pmod m, then:

  1. Addition Compatibility:
    a+c≡b+d(modm)a + c \equiv b + d \pmod m
  2. Multiplication Compatibility:
    a⋅c≡b⋅d(modm)a \cdot c \equiv b \cdot d \pmod m
  3. Exponentiation Compatibility:
    ak≡bk(modm)for any positive integer ka^k \equiv b^k \pmod m \quad \text{for any positive integer } k

3.4 Failure of General Cancellation

Unlike standard arithmetic over R\mathbb{R}, cancellation does not hold generally in modular arithmetic:
ac≡bc(modm)̸ ⁣  ⟹  a≡b(modm)ac \equiv bc \pmod m \quad \not\!\implies \quad a \equiv b \pmod m

Counterexample: 2⋅4≡2⋅1(mod6)2 \cdot 4 \equiv 2 \cdot 1 \pmod 6 (since 8≡2(mod6)8 \equiv 2 \pmod 6), but canceling the 22 gives 4≡1(mod6)4 \equiv 1 \pmod 6, which is false!

The Correct Cancellation Rule:
ac≡bc(modm)  ⟺  a≡b(modmgcd⁡(c,m))ac \equiv bc \pmod m \iff a \equiv b \pmod{\frac{m}{\gcd(c, m)}}
If gcd⁡(c,m)=1\gcd(c, m) = 1 (i.e., cc and mm are coprime), then cc can be cancelled safely:
ac≡bc(modm)  ⟹  a≡b(modm)(provided gcd⁡(c,m)=1)ac \equiv bc \pmod m \implies a \equiv b \pmod m \quad (\text{provided } \gcd(c, m) = 1)


4. Representations of Integers and Base Expansions

4.1 Base-bb Expansion Theorem

Let bb be an integer greater than 1 (the base or radix). Any positive integer nn can be uniquely expressed in the base-bb positional system as:

n=akbk+ak−1bk−1+...+a1b+a0n = a_k b^k + a_{k-1} b^{k-1} + ... + a_1 b + a_0

Where:

  • kk is a non-negative integer.
  • Each digit aia_i satisfies 0≤ai<b0 \le a_i < b.
  • The leading coefficient ak≠0a_k \neq 0.
  • Notation: n=(akak−1...a1a0)bn = (a_k a_{k-1} ... a_1 a_0)_b.

4.2 Algorithm for Base Conversion

To convert a decimal integer nn to base bb:

  1. Divide nn by bb to get quotient q0q_0 and remainder a0=n mod ba_0 = n \bmod b.
  2. Divide q0q_0 by bb to get q1q_1 and remainder a1a_1.
  3. Repeat until quotient becomes 00. The remainders read in reverse order (bottom-up) form the base-bb representation.

4.3 Common Cryptographic Number Bases

Base NameRadix (bb)Permitted DigitsPractical Computer Science Application
Binary22{0,1}\{0, 1\}Low-level hardware logic, bitwise XOR ciphers
Octal88{0,1,2,3,4,5,6,7}\{0, 1, 2, 3, 4, 5, 6, 7\}Unix file permissions (chmod 755)
Decimal1010{0,1,...,9}\{0, 1, ..., 9\}Human standard positional arithmetic
Hexadecimal1616{0,1,...,9,A,B,C,D,E,F}\{0, 1, ..., 9, A, B, C, D, E, F\}Memory addresses, cryptographic hashes (MD5, SHA-256)

Hexadecimal letter values: A=10,B=11,C=12,D=13,E=14,F=15A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.

4.4 Fast Conversion Shortcuts: Binary ↔\leftrightarrow Octal ↔\leftrightarrow Hexadecimal

Because 8=238 = 2^3 and 16=2416 = 2^4, conversion between binary and octal/hexadecimal requires zero arithmetic:

  • Binary to Octal: Partition binary bits into groups of 3 bits starting from the right (pad with leading zeros on left if needed), then replace each 3-bit group with its octal digit.
    • (11010111)2→(011)(010)(111)2=(327)8(11010111)_2 \rightarrow (011)(010)(111)_2 = (327)_8.
  • Binary to Hexadecimal: Partition binary bits into groups of 4 bits starting from the right, then replace each 4-bit group with its hexadecimal character.
    • (11010111)2→(1101)(0111)2=(D7)16(11010111)_2 \rightarrow (1101)(0111)_2 = (D7)_{16}.
  • Hexadecimal to Binary: Expand each hex digit into its corresponding 4-bit nibble.
    • (2AF)16=(0010)(1010)(1111)2=(1010101111)2(2AF)_{16} = (0010)(1010)(1111)_2 = (1010101111)_2.

5. Modular Exponentiation and Fast Algorithms

In modern cryptosystems (such as RSA c=me mod nc = m^e \bmod n and Diffie-Hellman A=ga mod pA = g^a \bmod p), numbers often have 2048 or 4096 bits. Calculating aba^b directly produces astronomical numbers exceeding the atoms in the observable universe.

5.1 Square-and-Multiply (Repeated Squaring) Algorithm

To compute ab mod ma^b \bmod m efficiently:

  1. Express the exponent bb in binary form: b=(bkbk−1...b1b0)2b = (b_k b_{k-1} ... b_1 b_0)_2.
  2. Initialize result x=1x = 1 and base power P=a mod mP = a \bmod m.
  3. For each bit from i=0i = 0 to kk:
    • If bit bi=1b_i = 1, update x=(x⋅P) mod mx = (x \cdot P) \bmod m.
    • Square the base power: P=(P⋅P) mod mP = (P \cdot P) \bmod m.
  4. Return xx.

Time Complexity: Requires at most 2log⁡2b2 \log_2 b modular multiplications (O(log⁡b)O(\log b) runtime), making computations feasible in milliseconds even for 4096-bit exponents.


Common Pitfalls & Anti-Patterns

  1. Negative Remainders: Writing −15=4⋅(−3)−3-15 = 4 \cdot (-3) - 3 instead of −15=4⋅(−4)+1-15 = 4 \cdot (-4) + 1. The remainder must strictly satisfy 0≤r<d0 \le r < d.
  2. Illegal Cancellation in Modulo: Assuming 4x≡4y(mod12)  ⟹  x≡y(mod12)4x \equiv 4y \pmod{12} \implies x \equiv y \pmod{12}. In truth, gcd⁡(4,12)=4\gcd(4, 12) = 4, so x≡y(mod3)x \equiv y \pmod 3.
  3. Misgrouping Bits for Base Conversion: Grouping from left to right instead of right to left when converting binary to octal or hex causes catastrophic padding errors.
  4. Dividing in Modular Arithmetic: Division by aa is undefined unless an explicit modular multiplicative inverse a−1(modm)a^{-1} \pmod m exists (which requires gcd⁡(a,m)=1\gcd(a, m) = 1).

Exam Tips & High-Yield Formulas

  • Division Algorithm: a=dq+ra = dq + r, with 0≤r<d0 \le r < d.
  • Congruence: a≡b(modm)  ⟺  m∣(a−b)  ⟺  a mod m=b mod ma \equiv b \pmod m \iff m \mid (a - b) \iff a \bmod m = b \bmod m.
  • Cancellation Rule: ac≡bc(modm)  ⟺  a≡b(modmgcd⁡(c,m))ac \equiv bc \pmod m \iff a \equiv b \pmod{\frac{m}{\gcd(c, m)}}.
  • Base Groupings: Binary to Octal = groups of 3 bits; Binary to Hex = groups of 4 bits (grouped from right to left).
  • Linearity: If a∣ba \mid b and a∣ca \mid c, then a∣(mb+nc)a \mid (mb + nc) for any integers m,nm, n.

Quick Revision Summary

  • Divisibility: a∣ba \mid b requires b=acb = ac. Divisibility is reflexive, transitive, and linear.
  • Division Algorithm: Uniquely breaks any integer aa into dq+rdq + r with strictly non-negative remainder 0≤r<d0 \le r < d.
  • Modulo System: Partitions integers into mm equivalence classes. Addition and multiplication are preserved; cancellation requires coprimality.
  • Base Expansions: Encodes integers into radix bb. Powers of 2 (23=8,24=162^3=8, 2^4=16) permit direct 3-bit and 4-bit regrouping.
  • Fast Exponentiation: Square-and-multiply evaluates ab mod ma^b \bmod m in logarithmic time O(log⁡b)O(\log b) by exploiting binary expansion.