This repository has been archived by the owner on Dec 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shank.py
70 lines (59 loc) · 1.47 KB
/
shank.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
def func_bs():
bs_array=[]
print("baby step = a * b ^ r mod c")
print("a:")
a=int(input())
print("b:")
b=int(input())
print("r:")
r=int(input())+1
print("c:")
c=int(input())
for i in range(r):
ans=((a*pow(b,i))%c)
print(i,"\t",ans)
bs_array.append(ans)
return bs_array
def func_gs():
gs_array=[]
print("giant step = b ^ m mod c")
print("b:")
b=int(input())
print("m:")
m=int(input())+1
print("c:")
c=int(input())
for i in range(m):
ans=(pow(b,i))%c
print(i,"\t",ans)
gs_array.append(ans)
return gs_array
def func_find(bs_array,gs_array):
print("baby step array : ")
print("[",end='')
for i in range(len(bs_array)):
print("(",i,",",bs_array[i],"),",end='')
print("]")
print("giant step array : ")
print("[",end='')
for i in range(len(gs_array)):
print("(",i,",",gs_array[i],"),",end='')
print("]")
for m in range(len(gs_array)):
for i in range(len(bs_array)):
if gs_array[m]==bs_array[i]:
print("r : ",i)
print("m : ",m)
return 0
while True:
print("1 : baby steps(right hand)")
print("2 : giant steps(left hand)")
print("3 : find same")
msg=int(input())
if msg==1:
bs_array=func_bs()
elif msg==2:
gs_array=func_gs()
elif msg==3:
func_find(bs_array,gs_array)