Skip to content

Commit b945fc3

Browse files
committed
refactor solver
1 parent 46b0ad8 commit b945fc3

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

2019-11-16-asis-finals/serifin/README.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,18 @@ We need to:
6060
def cubic_root_prime(c,p):
6161
F.<x> = PolynomialRing(Zmod(p), implementation='NTL')
6262
poly = x^3 - c
63-
return poly.roots()
63+
return [root for (root,_) in poly.roots()]
6464

6565
def cubic_composite_root(c, p, q):
66-
return cubic_root_prime(c,p), cubic_root_prime(c, q)
66+
rootsp, rootsq = cubic_root_prime(c,p), cubic_root_prime(c, q)
67+
return [CRT([int(rp), int(rq)],[p,q]) for rp, rq in itertools.product(rootsp, rootsq)]
6768
```
6869

6970
The last part is simply to take every possible combination of the roots and check if it's the right flag:
7071

7172
```python
7273
c = 78643169701772559588799235367819734778096402374604527417084323620408059019575192358078539818358733737255857476385895538384775148891045101302925145675409962992412316886938945993724412615232830803246511441681246452297825709122570818987869680882524715843237380910432586361889181947636507663665579725822511143923
73-
rootsp, rootsq = cubic_composite_root(c,p,q)
74-
print('roots', rootsp, rootsq)
75-
for rp, rq in itertools.product(rootsp, rootsq):
76-
solution = CRT([int(rp), int(rq)],[p,q])
74+
for solution in cubic_composite_root(c,p,q):
7775
flag = long_to_bytes(solution)
7876
if "ASIS" in flag:
7977
print(flag)

2019-11-16-asis-finals/serifin/solver.sage

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,15 @@ def cubic_root_prime(c,p):
2727
return [root for (root,_) in poly.roots()]
2828

2929
def cubic_composite_root(c, p, q):
30-
return cubic_root_prime(c,p), cubic_root_prime(c, q)
31-
30+
rootsp, rootsq = cubic_root_prime(c,p), cubic_root_prime(c, q)
31+
return [CRT([int(rp), int(rq)],[p,q]) for rp, rq in itertools.product(rootsp, rootsq)]
32+
3233
def main():
3334
N = 420908150499931060459278096327098138187098413066337803068086719915371572799398579907099206882673150969295710355168269114763450250269978036896492091647087033643409285987088104286084134380067603342891743645230429893458468679597440933612118398950431574177624142313058494887351382310900902645184808573011083971351
3435
p,q = find_factors(N)
3536
print('primes', p,q)
3637
c = 78643169701772559588799235367819734778096402374604527417084323620408059019575192358078539818358733737255857476385895538384775148891045101302925145675409962992412316886938945993724412615232830803246511441681246452297825709122570818987869680882524715843237380910432586361889181947636507663665579725822511143923
37-
rootsp, rootsq = cubic_composite_root(c,p,q)
38-
print('roots', rootsp, rootsq)
39-
for rp, rq in itertools.product(rootsp, rootsq):
40-
solution = CRT([int(rp), int(rq)],[p,q])
38+
for solution in cubic_composite_root(c,p,q):
4139
flag = long_to_bytes(solution)
4240
if "ASIS" in flag:
4341
print(flag)

0 commit comments

Comments
 (0)