Basic knowledge of cryptography - number theory (from entry to abandonment)

Knowledge of number theory

This article mainly introduces divisibility, prime numbers and composite numbers, congruence theorem, modular inverse elements, Euclidean division, Euler function, Euler's theorem, Fermat's little theorem, Chinese remainder theorem (Sun Tzu's theorem).



Introduction

Recently, I learned the public key algorithm, which involves some knowledge in number theory. Summarize some basic knowledge of number theory.

  • gcd is the greatest common divisor.
  • lcm is the least common multiple.

1. Divisibility

a, b are any two integers, b is not 0, and there is an integer q such that a=qb. Write it as: b|a

2. Prime and Composite Numbers

n has no other factors than the trivial divisors ±1 and ±n. Then n is a prime number (a prime number is also called a prime number), otherwise it is a composite number. For example (3, 7, 11, 13 are all prime numbers)

  • 1 is neither prime nor composite.
  • Two numbers are relatively prime: they have no common factors other than 1. If the greatest common factor of a and n is 1, it can be written as gcd(a, n)=1.
  • There are infinitely many prime numbers

The status of prime numbers in cryptography is still very high.


3. The same corollary

  • Given a positive integer, a, b are two integers, m|ab, then a, b modulo m congruence, recorded as a≡b(mod n).

  • Theorem: Suppose m is a positive integer, a and b are two positive integers, then the necessary and sufficient condition for a≡b(modm) is that there is an integer k such that a=b+km.

  • For positive integer n, integers a1, a2, b1, b2, if
    a1≡a2 (mod n). b1≡b2 (mod n)
    , then we can get the following properties:
    a1+b1= a2+ b2 (mod n)
    a1·b1= a2 b2 (mod n)

Modular inverse element

For an integer a and a positive integer n, the modular inverse element of a to the modulus n refers to the integer b satisfying the following conditions.
ab≡1(mod n)

The modular inverse elements of a to the modulus n do not necessarily exist, and the necessary and sufficient condition for the existence of the modular inverse elements of a to the modulus n is that a and n are mutually prime


Four, Euclid (Euclidean) division

a, b are two integers, b>0. There is a unique q, r such that: a=qb+r. You can use the Euclidean algorithm (also known as the rolling and dividing method) to find the greatest common factor of two numbers.

The greatest common factor can be found by rolling and dividing

gcd(a,b)=gcd(a−b,b)

eg:gcd(4864,3458)=38
4864 = 3458+1406
3458 = 21406+646
1406 = 2
646+114
646 = 5114+76
114 = 1
76+38
76 = 2*38

If minimum non-negative remainder is replaced by absolute value minimum remainder. The number of calculations may be reduced, thereby reducing calculation time.

6. Euler function

Assuming that n is a positive integer, the number of n integers 0, 1, ..., m-1 that are relatively prime to m is recorded as Φ(n) eg: Φ(2)=1; Φ(1
) =1

  • If p is a prime number then Φ( p )=p-1
  • If p and q are different prime numbers, then Φ( p*q )=(p-1)(q-1)=Φ( p )Φ( q )

Euler's theorem

For each coprime a and n, that is, gcd(a,n)=1, we can get: a^Φ(n) ≡1(mod)n

7. Fermat's little theorem

If p is a prime number and the integer a is not a multiple of p (ie gcd(a,p)=1), then a^(p-1)≡1(mod p) or a^ϕ(m)≡1 mod (m).
Fermat's little theorem is a special case of Euler's theorem

8. Chinese Remainder Theorem CRT

It was first seen in "Sun Tzu's Suan Jing" (Chinese mathematics works in the Southern and Northern Dynasties, AD 420-589), which is called the problem of not knowing the number of things, also known as the problem of Han Xin's ordering soldiers. Also known as Sun Tzu's theorem.

Today there are things whose number is not known, three or three leaves two, five or five leaves three, seven or seven leaves two. Ask about geometry?

In fact, it is to solve a first-order congruence equation.
insert image description here
The process of solving can refer to the following link: Chinese Remainder Theorem (CRT)
written by the author is very simple and easy to understand.
Chinese remainder theorem

Summarize

For this part of the study, the author is just a simple introduction, and the knowledge points involved are very basic. Recommend a useful tool: sagemath.

Reference article: Fundamentals of Cryptography 1: Comprehensive Analysis of RSA Algorithm Principles
Chinese Remainder Theorem (CRT)

Guess you like

Origin blog.csdn.net/qq_43589852/article/details/127411431