-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add stub of approximate-gcd-experiment
- Loading branch information
Showing
13 changed files
with
970 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Approximate GCD の実験 | ||
CTF の問題 Sign (ISITDTU CTF QUALS 2024) についての解析。問題内容は https://docs.google.com/spreadsheets/d/1nmj0uAPWkWbC0uXBoA7eBef_a6cRJ-UgTDuuh0gAc2Y/edit?usp=sharing を見ること。 | ||
|
||
解析した結果のスプレッドシートは https://docs.google.com/spreadsheets/d/1nmj0uAPWkWbC0uXBoA7eBef_a6cRJ-UgTDuuh0gAc2Y/edit?usp=sharing である。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
def approx_gcd(d: list[int], approx_error: int) -> int: | ||
""" | ||
Returns q where d[0] ~= qx and d[i]'s are close to multiples of x. | ||
The caller must find (d[0] + q // 2) // q if they want to find x. | ||
""" | ||
l = len(d) | ||
M = Matrix(ZZ, l, l) | ||
M[0, 0] = approx_error | ||
for i in range(1, l): | ||
M[0, i] = d[i] | ||
M[i, i] = -d[0] | ||
L = M.LLL() | ||
for row in L: | ||
if row[0] != 0: | ||
quot = abs(row[0] // approx_error) | ||
return quot |
Oops, something went wrong.