On the basis of the number of secondary school on password
1. modular arithmetic
Modular arithmetic modulo operation may also be referred to as, e.g. 23≡11 (mod12), so if a = kn + b, may be expressed as a ≡ b (mod n), computing rules:
(a+b) mod n = ((a mod n) + (b mod n))mod n
(a*b) mod n = ((a mod n) * (b mod n)) mod n
- Complete set of the remaining
1 ~ n-1 constitute a complete set of remaining natural number n, for any integer m% n are present in the collection of 1 ~ n.
- Adder chain configuration
In the encryption algorithm, applied to a large number of modulo operation mode for a k bit number n, all operations such as addition, subtraction of the intermediate structure will not exceed 2k bits, for example, A X MOD n-calculation will be greatly simplified when the complexity.
E.g. A . 8 MOD n-can be calculated in the calculation ((A 2 MOD n-) 2 MOD n-) 2 MOD n-
When the index x is not a multiple of 2 is required adder chain configuration, e.g. 25, 25 = 16 + 8 + 1 = 2 . 4 + 2 3 + 2 0
Thus A 25 MOD n-= (A * A . 8 * A 16 ) n-MOD = ((((A 2 * A) 2 ) 2 ) 2 * A) n-MOD
C language representation
unsigned long ss(unsigned long x , unsigned long y , unsigned long n) { unsigned long s,t,u; int i ; s = 1; t =x ; u=y; while(u){ if(u&1) s = (s*t)&n; u>>=1; t = (t*t) % n ; } return (s); }
- Prime numbers
The greatest common divisor (GCD)
gcd(4,2)=2 gcd(4,3)=1 gcd(6,4)=2
c Language:
int gcd(int x,int y){ int m; while(x>0){ m = x; x = x%y; y = m; } return m
- Inverse mode
Inverse:
Equation Solutions called modulo inverse, when (i.e. , prime), then the equation has a unique solution, or no solution.
Then the inverse can be used to do it, for example , and no , but in addition will direct the explosion accuracy, then we can use the inverse, assuming a representative of inverse, then .
Inverse mode:
4 * x ≡ 1 (mod 7), i.e. 4x = 7k + 1
More common problems are: 1 = (a * x) mod n can be written A -1 ≡ X (n-MOD)
Therefore, there is a solution set of problems here:
When the GCD (A, n-) =. 1, A -1 ≡ X (n-MOD) a unique solution
When the GCD (A, n-). 1 A ≠ -1 ≡ X (n-MOD) no solution
How to find the inverse of a% n, and expand the use of the Euclidean algorithm
void e_gcd(int a, int b, int &gcd, int &x, int &y) { if (b == 0) { x = 1; y = 0; gcd = a; } else { e_gcd(b, a % b, gcd, y, x); y -= x * (a / b) } }
- Fermat's Little Theorem
This theorem is often encountered in junior high school math league, before seemingly had also seen the high school league, but the CMO as a basis for writing a bit.
Content: if m is a prime number, and is not a multiple of m, then there is a theorem m. 1- ≡. 1 (MOD m)
- Euler function
Euler function: φ (n) indicates the number mutually prime number with n from 1 ~ n-1. φ (1) = 1, the general term formulas: φ (n) = n * (1-1 / p1) * (1-1 / p2) * (1-1 / p3) * (1-1 / p4) ... .. (1-1 / pn)
Wherein p1 ~ pn prime factors of n.
In some encryption algorithms, secret key generation process is the process of computing the Euler function.
- Discrete logarithm over finite fields
Die index is frequently used in another way function Cryptography
For example:. 3 X ≡ MOD. 17 15, X =. 6
Not all of the discrete logarithm has a corresponding solution for example. 3 x ≡ 13 is no integer x MOD. 7 may comply with the formula, so that no solution to the discrete logarithm. On the discrete logarithm of domain present in two cases:
1. The multiplicative group of prime domain
2. The elliptic curve group of finite field
1. modular arithmetic
Modular arithmetic modulo operation may also be referred to as, e.g. 23≡11 (mod12), so if a = kn + b, may be expressed as a ≡ b (mod n), computing rules:
(a+b) mod n = ((a mod n) + (b mod n))mod n
(a*b) mod n = ((a mod n) * (b mod n)) mod n
- Complete set of the remaining
1 ~ n-1 constitute a complete set of remaining natural number n, for any integer m% n are present in the collection of 1 ~ n.
- Adder chain configuration
In the encryption algorithm, applied to a large number of modulo operation mode for a k bit number n, all operations such as addition, subtraction of the intermediate structure will not exceed 2k bits, for example, A X MOD n-calculation will be greatly simplified when the complexity.
E.g. A . 8 MOD n-can be calculated in the calculation ((A 2 MOD n-) 2 MOD n-) 2 MOD n-
When the index x is not a multiple of 2 is required adder chain configuration, e.g. 25, 25 = 16 + 8 + 1 = 2 . 4 + 2 3 + 2 0
Thus A 25 MOD n-= (A * A . 8 * A 16 ) n-MOD = ((((A 2 * A) 2 ) 2 ) 2 * A) n-MOD
C language representation
unsigned long ss(unsigned long x , unsigned long y , unsigned long n) { unsigned long s,t,u; int i ; s = 1; t =x ; u=y; while(u){ if(u&1) s = (s*t)&n; u>>=1; t = (t*t) % n ; } return (s); }
- Prime numbers
The greatest common divisor (GCD)
gcd(4,2)=2 gcd(4,3)=1 gcd(6,4)=2
c Language:
int gcd(int x,int y){ int m; while(x>0){ m = x; x = x%y; y = m; } return m
- Inverse mode
Inverse:
Equation Solutions called modulo inverse, when (i.e. , prime), then the equation has a unique solution, or no solution.
Then the inverse can be used to do it, for example , and no , but in addition will direct the explosion accuracy, then we can use the inverse, assuming a representative of inverse, then .
Inverse mode:
4 * x ≡ 1 (mod 7), i.e. 4x = 7k + 1
More common problems are: 1 = (a * x) mod n can be written A -1 ≡ X (n-MOD)
Therefore, there is a solution set of problems here:
When the GCD (A, n-) =. 1, A -1 ≡ X (n-MOD) a unique solution
When the GCD (A, n-). 1 A ≠ -1 ≡ X (n-MOD) no solution
How to find the inverse of a% n, and expand the use of the Euclidean algorithm
void e_gcd(int a, int b, int &gcd, int &x, int &y) { if (b == 0) { x = 1; y = 0; gcd = a; } else { e_gcd(b, a % b, gcd, y, x); y -= x * (a / b) } }
- Fermat's Little Theorem
This theorem is often encountered in junior high school math league, before seemingly had also seen the high school league, but the CMO as a basis for writing a bit.
Content: if m is a prime number, and is not a multiple of m, then there is a theorem m. 1- ≡. 1 (MOD m)
- Euler function
Euler function: φ (n) indicates the number mutually prime number with n from 1 ~ n-1. φ (1) = 1, the general term formulas: φ (n) = n * (1-1 / p1) * (1-1 / p2) * (1-1 / p3) * (1-1 / p4) ... .. (1-1 / pn)
Wherein p1 ~ pn prime factors of n.
In some encryption algorithms, secret key generation process is the process of computing the Euler function.
- Discrete logarithm over finite fields
Die index is frequently used in another way function Cryptography
For example:. 3 X ≡ MOD. 17 15, X =. 6
Not all of the discrete logarithm has a corresponding solution for example. 3 x ≡ 13 is no integer x MOD. 7 may comply with the formula, so that no solution to the discrete logarithm. On the discrete logarithm of domain present in two cases:
1. The multiplicative group of prime domain
2. The elliptic curve group of finite field