Skip to content

Commit

Permalink
Add stub of approximate-gcd-experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Nov 2, 2024
1 parent 1051fad commit 6404eca
Show file tree
Hide file tree
Showing 13 changed files with 970 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .github/workflows/check_scripts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint -r algorithm/smart-attack/requirements.txt
pip install pylint mypy -r algorithm/smart-attack/requirements.txt
- name: Set up Go
uses: actions/setup-go@v4
Expand All @@ -30,6 +30,8 @@ jobs:
pylint algorithm/smart-attack/smart_attack.py --fail-under=9
python algorithm/smart-attack/smart_attack.py test
pylint algorithm/ecpp/binary_quad.py --fail-under=9
pylint algorithm/approximate-gcd-experiment/gen_rsa.py --fail-under=9
mypy algorithm/approximate-gcd-experiment/gen_rsa.py
- name: Check scripts in general
run: |
Expand Down
4 changes: 4 additions & 0 deletions algorithm/approximate-gcd-experiment/README.md
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 である。
16 changes: 16 additions & 0 deletions algorithm/approximate-gcd-experiment/approx_gcd.sage
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
Loading

0 comments on commit 6404eca

Please sign in to comment.