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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
import hashlib
import gmpy2
from Crypto.Util.number import *
r1=6052579169727414254054653383715281797417510994285530927615
#curve_192
p=6277101735386680763835789423207666416083908700390324961279
a=-3
b=2455155546008943817740293915197451784769108058161191238065
def convert_to_base(n, b):
if n < 2:
return [n]
temp = n
ans = []
while temp != 0:
ans = [temp % b] + ans
temp //= b
return ans
def cipolla(n, p):
n %= p
if n == 0 or n == 1:
return [n, (p - n) % p]
phi = p - 1
if pow(n, phi // 2, p) != 1:
return []
if p % 4 == 3:
ans = int(pow(n, (p + 1) // 4, p))
return [ans, (p - ans) % p]
aa = 0
for i in range(1, p):
temp = pow(((i * i - n) % p), phi // 2, p)
if temp == phi:
aa = i
break
exponent = convert_to_base((p + 1) // 2, 2)
def cipolla_mult(ab, cd, w, p):
a, b = ab
c, d = cd
return (a * c + b * d * w) % p, (a * d + b * c) % p
x1 = (aa, 1)
x2 = cipolla_mult(x1, x1, aa * aa - n, p)
for i in range(1, len(exponent)):
if exponent[i] == 0:
x2 = cipolla_mult(x2, x1, aa * aa - n, p)
x1 = cipolla_mult(x1, x1, aa * aa - n, p)
else:
x1 = cipolla_mult(x1, x2, aa * aa - n, p)
x2 = cipolla_mult(x2, x2, aa * aa - n, p)
return [x1[0], (p - x1[0]) % p]
y12=(r1**3+a*r1+b)%p
print(cipolla(y12, p))
# sage
E = EllipticCurve(GF(p),[a,b])
G = E(602046282375688656758213480587526111916698976636884684818,174050332293622031404857552280219410364023488927386650641)
p1 = E(6052579169727414254054653383715281797417510994285530927615, 5871535981004787479780408408652175440419840647034147933664)
a,b,w,X=751818 ,1155982, 908970521, 20391992
z=p1+(-w)*G+(-a)*X*p1+(-b)*X*G
#z = (k1 - w * t) * G + (-a * k1 - b) * Y
print(z)
zx=2879837810202640866238433125146194557887945787271835955457
k2 = int(hashlib.sha1(str(zx).encode()).hexdigest(), 16)
print(k2)
p = k2
for i in range(99):
p = gmpy2.next_prime(p)
q = gmpy2.next_prime(p)
print(p,q)
#
p=1370020847323284147745373471297398364094203631317
q=1370020847323284147745373471297398364094203631323
phi=(p-1)*(q-1)
d=inverse(65537, phi)
n=p*q
c=1294716523385880392710224476578009870292343123062352402869702505110652244504101007338338248714943
for i in range(2**16):
if b'flag' in long_to_bytes(pow(c,d, p*q)+n*i):
print(long_to_bytes(pow(c,d, p*q)+n*i))
|