EZ

Eduzan

Learning Hub

Eduzan
Eduzan / Cyber Security

Introduction to Number Theory

Fermat’s Little Theorem is a fundamental theorem in number theory that states:
If p is a prime number and a is any integer not divisible by p, then:

Fermat's Little Theorem

In other words, the remainder when   is divided by p is 1.

This theorem is widely used in public-key cryptography algorithms like RSA, primarily to perform efficient modular exponentiation and check for primality.

Why Fermat’s Little Theorem?

In RSA, Fermat’s Little Theorem simplifies computations by reducing powers modulo a prime. This efficiency is critical in real-world cryptography, where numbers are extremely large (hundreds of digits). Fermat’s theorem ensures correctness and efficiency in these computations.

 Fermat’s Little Theorem
 Fermat’s Little Theorem

Application in RSA Cryptography

RSA relies on modular arithmetic, and Fermat’s Little Theorem provides a shortcut to compute powers modulo ppp, which is computationally expensive for large numbers.

Key Steps in RSA Using Fermat’s Little Theorem:

  1. Key Generation:
    • Choose two large prime numbers p and q.
    • Compute     (the modulus).
    • Calculate ϕ(n)= (p−1)(q−1) (Euler’s totient function).
    • Select an encryption key eee such that   and 
    • Compute the decryption key d such that  (modular inverse).
  2. Encryption:
    • Given a plaintext M, compute the ciphertext C using 
    • Decryption:
      • Retrieve the plaintext M from C   
Decryption:

Example: Using Fermat’s Little Theorem

Problem: Encrypt and decrypt a message using RSA with Fermat’s Little Theorem.

  1. Key Generation:
    • Choose p=7, q=11 (prime numbers).
    • Compute n=7 × 11= 77
    • Compute 
    • Choose e=1 (public key, gcd(17, 60) = 1)
    • Compute  
  2. Encryption:
    • Message M=8.
    • Compute  
    •   So, C=43
  3. Decryption:
    • Compute  M                      
    • Continue reducing until  
    • Recovered message M=8 

Output

  1. Public Key: (e,n) = (17,77)
  2. Private Key: (d,n) = (53,77)
  3. Ciphertext: C=43C = 43C=43
  4. Decrypted Message: M = 8
End of lesson.