2019-01-16Original-language archivelegacy assets may be incomplete
背景知识
自然数的集合论定义:
a+:=a∪{a}
归纳集
∅∈A
∀a(a∈A→a+∈A)
N 为所有归纳集之交
Peano 结构
e∈S
∀a∈S,f(a)∈S
∀b∈S,∀c∈S,f(b)=f(c)→b=c
∀a∈S,f(a)=e
∀A⊆S,(e∈A∧(∀a∈A)(f(a)∈A))→A=S
良序公理与数学归纳法原理等价
数论基础
带余除法: a=bq+r,b>0,0≤r<b
存在性证明:良序公理
唯一性证明
整除及其性质
a∣b,a∣c⇒a∣nb+mc
最大公因子 (hcf/gcd)
裴蜀定理:gcd(a,b)=ar+bs
证明:良序公理+带余除法
Strong Duality for GCD: max{di:d∈Z,d∣a,d∣b}=min{ax+by:x∈Z,y∈Z,ax+by>0}
证明
d∣s,s∣d
Weak Duality + ∃
唯一性证明
lcm(a,b)gcd(a,b)=ab
证明
Isomorphism Theorem
Unique Factorization
d∣(a,b)⇔d∣[a,b]ab
(a,b,c)[a,b,c]=[(a,b),(b,c),(c,a)]abc
[a,b,c]=(a,b)(a,c)(b,c)abc(a,b,c)
gcd(a,b,c)=gcd(gcd(a,b),c)
质数
π(x)∼lnxx
无限质数证明
P=p1p2⋯pn+1
Fermat Numer Fn=22n+1 两两互素
Fn−2=∏k=1n−1Fk
Mersenne Number 2p−1
2p≡1(modq)⇒p∣q−1
Dirichlet's Theorem: gcd(a,m)=1 then there are infinitely many primes p,p≡a(modm)
筛法求素数
算术基本定理
存在性证明:良序公理(找不满足中最小的)
唯一性证明:1→n
φ(n)=n∏p∣n(1−p1),p is prime
φ(p)=p−1
φ(n)>eγlnlnn+lnlnn3n,γ=0.577
Additivie group module n: (Zn,+n)
⟨a⟩=⟨(a,n)⟩
∣⟨a⟩∣=(a,n)n
Multiplicative group module n: (Zn∗,⋅n)
ord(a): the smallest possible integer that a(t)=e
ord(a)=∣⟨a⟩∣
Primitive root: a,ordm(a)=φ(m)
Number: if exists, φ(φ(m))
Euler's Theorem: aφ(n)≡1(modn)
Fermat's Theorem: ap−1≡1(modp)
Wilson Theorem: (p−1)!≡−1(modp)⟺p is prime
quadratic residue
a is quadratic residue x2=a(modp) has a solution for x
2p−1 quadratic residues for p
Legendre symbol (pa)=1 if a is a quadratic residue otherwise −1
(pa)≡a(p−1)/2(modp)
Modular linear equations
ax≡b(modn)
有解:d=gcd(a,n)∣b
求解:
ax+bn=d
x0=dxb
x1=x0+idn,i=0,⋯,n−1
CRT (The Chinese remainder theorem)
n=n1n2⋯nk, where ni are pairwise relatively prime, then we have mapping a↔(a1,a2,⋯,ak), for ⋅=+/−/∗, we have (a⋅b)(modn)↔((a1⋅b(modn1),⋯,(ak⋅bk)(modnk)))
→: direct
←
mi=nin
a≡(∑i=1kaimi(mi−1(modni)))(modn)
一般同余方程
法一:
有解:ai≡aj(mod(ni,nj))
先拆后合(相同或倍数)
x≡a(modni)⟺x≡C(mod[n1,⋯,nk])
法二:
两两合并
简化计算:
2300mod319
319=11∗29 + CRT
数论算法
model: multplying two β-bit integers take Θ(β2) bit operations
Euclid Algorithm
int ext_gcd(int a, int b, int &x, int &y){ if (b==0) { x = 1; y = 0; return a; } else { int ret = ext_gcd(b,a%b,y,x); y -= x*(a/b); return ret; }}
a>b≥1 and Euclid(a,b) performs k≥1 recursive calls, then a≥Fk+2,b≥Fk+1
证明:a≥b+(amodb)
Lame's Theorem: k≥1,a>b≥1,b<Fk+1 then Euclid makes fewer than k recursive calls
Fk∼5ϕk,ϕ=21+5
O(lgb)
Modular Exponentiation
int fp(int a, int b, int mod){ int c = 1; for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod; return c%mod;}
n is an odd composite number, then the number of witnesses to the compositeness of n is at least 2n−1
P(MILLER-RABIN errs)<2−s
P(prime∣RETURN prime)>0.5 if s>lg(lnn−1)
applicable: s=50
LL multimod(LL a, LL b, LL mod) { a %= mod; b %= mod; LL res = 0; while (b) { if (b & 1) { res += a; if (res >= mod) res -= mod; } b >>= 1; a <<= 1; if (a >= mod) a -= mod; } return res;}bool witness(LL s, LL n) { LL u = n - 1, t = 0; while ((u & 1) == 0 && u != 0) u >>= 1, t++; LL x = fp(s, u, n), tmp; while (t--) { tmp = x; x = multimod(x, x, n); if (x == 1 && tmp != n - 1 && tmp != 1) return true; } if (x != 1) return true; else return false;}bool millerrabin(LL n, const int times = 3) { if (n == 2) return true; if ((n & 1) == 0 || n < 2) return false; int i = times; while (i--) { LL x = random(2, n - 1); if (witness(x, n)) return false; } return true;}
Integer factorization
Trial division R→R2
Pollard's rho heuristic R→R4
initial: x1=random(0,n−1),y=x1,k=2
Loop
xi=xi−12(modn)
if gcd(y−xi,n)=1/n finded
if i==k
y=xi
k=2k
Crypotography
Private Key Crypotography
affine cryptosystem: f(p)=ap+b(modn)
polyalphabetic crypotosystem
German ADFGVX Field Cipher
Kerckhoffs's principle
Public Key Crypotography
f−1 must be difficult to compute
PKC
Self P,D
Others P′,D′
Message M
公钥加密
encoding with P′: P′(M) -> send
receive -> decoding with D′(P′(M))
数字签名
signing with D: M′=M+D(M)
(encrypt and) send -> receive (and decode)
verifying M=P(D(M))
RSA
n=pq
(E,φ(n))=1
DE≡1(modφ(n))
public: (n,E)
secret: (n,D)
encoding: y=xEmodn
decoding: x=yDmodn
DH(Deffie-Hellman)
a: small prime
p: large prime
Agent a: (Xa,Ya=aXamodp)
Agent b: (Xb,Yb=aXbmodp)
secret key: K=YbXamodp=YaXbmodp
Attack
Small e Attack: e=3,d obtained
Result: p,q leaks
ed=1+kφ(n),k∈Z,k<min{e,d}
Common Modulus Attack: (ei,ej)=1
Result: if message decoded both sent, original message can be recovered