GF(P) - Galois Fields
Module 02 / Lesson 04
Video Tutorial
What is GF(P)?
GF(P) or Galois Field of prime order is a finite mathematical field containing exactly p elements (where p is a prime number). It provides a structured way to perform arithmetic within a finite set.
Key Components:
- Prime number p
- Set: {0, 1, 2, ..., p-1}
- Modular Arithmetic
- Closed algebraic operations
Core Rules:
- All results are (mod p)
- Every non-zero element has an inverse
- Division uses multiplicative inverse
GF(5) Operation Examples:
• Addition: 3 + 4 = 7 mod 5 = 2
• Multiplication: 3 * 4 = 12 mod 5 = 2
• Inverse: Since (2 * 3) mod 5 = 1, then 3 is the inverse of 2
Python GF(P) Operations
def gf_op(a, b, p, op):
if op == '+': return (a + b) % p
if op == '-': return (a - b) % p
if op == '*': return (a * b) % p
if op == '/':
# Modular inverse using pow(base, exp, mod)
# In GF(p), a^(-1) = a^(p-2) mod p
inv = pow(b, p - 2, p)
return (a * inv) % p
# Example: In GF(5)
p = 5
print(f"3 + 4 in GF(5): {gf_op(3, 4, p, '+')}") # Result: 2
print(f"Division 1 / 2 in GF(5): {gf_op(1, 2, p, '/')}") # Result: 3