Closed dani0104 closed 2 years ago
You don't need to brute force any bits for this challenge, you've got enough bits to solve it. If you want to debug whether it would work or not, you can do the following:
import logging
logging.basicConfig(format='%(asctime)s.%(msecs)03d %(levelname)s {%(module)s} [%(funcName)s] %(message)s', datefmt='%Y-%m-%d,%H:%M:%S', level=logging.DEBUG)
from shared import small_roots
small_roots.DEBUG_ROOTS = [0x777ee137, 0x890f7324, 0x65e8bb1cff] # Note the order is reversed here
You'll then get an output similar to this:
2022-02-11,19:00:34.016 INFO {coppersmith} [factorize_p] Trying m = 5, t = 1...
2022-02-11,19:00:34.023 DEBUG {herrmann_may_multivariate} [modular_multivariate] Generating shifts...
2022-02-11,19:00:34.025 DEBUG {__init__} [fill_lattice] Filling the lattice (56 x 56)...
2022-02-11,19:00:34.269 DEBUG {__init__} [reduce] Executing the LLL algorithm...
2022-02-11,19:00:52.405 DEBUG {__init__} [reconstruct_polynomials] Reconstructing polynomials...
2022-02-11,19:00:52.418 DEBUG {__init__} [reconstruct_polynomials] Original polynomial divides reconstructed polynomial at row 0, dividing...
2022-02-11,19:00:52.418 DEBUG {__init__} [reconstruct_polynomials] Polynomial at row 0 is constant, ignoring...
2022-02-11,19:00:52.425 DEBUG {__init__} [reconstruct_polynomials] Polynomial at row 1 roots check: 0
2022-02-11,19:00:52.432 DEBUG {__init__} [reconstruct_polynomials] Polynomial at row 2 roots check: 0
2022-02-11,19:00:52.438 DEBUG {__init__} [reconstruct_polynomials] Polynomial at row 3 roots check: 0
...
This tells you which reconstructed polynomials have integer roots in the provided roots. If all of them are non-zero, then you should select a higher m
value (or maybe a higher t
value, but this works rarely). If most of them (excluding the couple last ones) are 0, then the Groebner basis method will automatically find the roots. If most of them are 0, but there are a couple of non-zero ones first, you can manually pick the right polynomials and perform the Groebner basis reduction yourself. However, this requires a lot of hacking in the code.
Once you can solve it for the example values (without brute forcing here), it shouldn't be too hard to solve the actual challenge
Wow! after debugging I realized all I needed to do was change m
from 5 to 6, for whatever reason 5 takes much much longer than 6 on the actual values I need (and example values too), like it should still work with 5 based on my testing, but it's so much slower it's unbelievable (contrary to what I expected).
Challenged solved now, but care to explain why it might work much faster on m=6
than m=5
?
(at least with both values I provided, example values and challenge values)
Never mind after some more debugging I noticed that when m=5
another sneaky number besides the last few was non zero, I get why it failed.
Never mind after some more debugging I noticed that when
m=5
another sneaky number besides the last few was non zero, I get why it failed.
Right, the issue is that the root finding method can't know that without also knowing the roots. Heuristically, the first ones should always be zero, but sometimes it's not the case.
Hey it's me from the email again. I've been trying to solve corrupt-key-2 from PicoGym
I'm using an example I generated myself, I added the code below to the end of the coppersmith.py file
My question is why at times these lines seem to get executed in less than half a minute, and other times they take way too long for me to measure? I'm asking this because I'm trying to bruteforce bits of the prime, but I can't figure out which bits should I bruteforce for most efficiency These are the actual values I have (the ones above are just for testing):