update notes

This commit is contained in:
Zheyuan Wu
2024-11-18 14:16:15 -06:00
parent f08d8ff674
commit 5281b8270f
45 changed files with 4404 additions and 2 deletions

View File

@@ -151,10 +151,15 @@ A group $G$ is a set of elements with a binary operator $\oplus:G\times G\to G$
$$
\Phi(p)=p-1
$$ if $p$ is prime
$$
if $p$ is prime
$$
\Phi(N)=(p-1)(q-1)
$$ if $N=pq$ and $p,q$ are primes
$$
if $N=pq$ and $p,q$ are primes
#### Theorem 47.10

65
pages/CSE442T/fun.py Normal file
View File

@@ -0,0 +1,65 @@
from math import gcd
def euclidean_algorithm(a,b):
if a<b: return euclidean_algorithm(b,a)
if b==0: return a
return euclidean_algorithm(b,a%b)
def get_generator(p):
"""
p should be a prime
"""
f=3
g=[]
for i in range(1,p):
sg=[]
step=p
k=i
while k!=1 and step>0:
if k==0:
break
# raise ValueError(f"Damn, {i} generates 0 for group {p}")
sg.append(k)
k=(k**f)%p
step-=1
sg.append(1)
# if len(sg)!=(p-1): continue
g.append((i,[j for j in sg]))
return g
def __list_print(arr):
for i in arr:print(i)
def factorization(n):
# Pollard's rho integer factorization algorithm
# https://stackoverflow.com/questions/32871539/integer-factorization-in-python
factors = []
def get_factor(n):
x_fixed = 2
cycle_size = 2
x = 2
factor = 1
while factor == 1:
for count in range(cycle_size):
if factor > 1: break
x = (x * x + 1) % n
factor = gcd(x - x_fixed, n)
cycle_size *= 2
x_fixed = x
return factor
while n > 1:
next = get_factor(n)
factors.append(next)
n //= next
return factors
if __name__=='__main__':
print(euclidean_algorithm(285,(10**9+7)*5))
__list_print(get_generator(23))
print(factorization(162000))