-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathod.py
39 lines (35 loc) · 1.05 KB
/
od.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from toolkit import *
p = 31
if __name__ == '__main__':
simplified_redundant = []
for i in range(1, p):
if gcd(i, p) == 1:
simplified_redundant.append(i)
print(simplified_redundant)
# find a st. gcd(a, m) =1
# only a i n simplified_redundant can have ord
ordpa = []
for a in simplified_redundant: # range contains the first exclude the last
ordpa.append(ord(p, a))
print(ordpa)
glst = []
for i in range(len(simplified_redundant)):
if ordpa[i] == phi(p):
glst.append(simplified_redundant[i])
print(glst)
g = glst[0]
gk = []
for k in range(p - 1):
gk.append(pow(g, k, p))
print(gk)
# write_gk_table(gk, p)
alst = [11, 11, 17]
blst = [19, 20, 19]
for a in alst:
for b in blst:
guv_idx = (gk.index(a) + gk.index(b)) % (p - 1)
guv = gk[guv_idx]
if guv == a * b % p:
print('√', end='')
else:
print('×', end='')