Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CVP.babai: search for correct row instead of assuming it's -1 #291

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/fpylll/algorithms/babai.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def babai(B, t, *args, **kwargs):
>>> _ = LLL.reduction(B)
>>> v == CVP.closest_vector(B, t)
True

>>> from fpylll import *
>>> A = [428812188057600, 1, 0, 409148314550272, 0, 1]
>>> A = IntegerMatrix.from_iterable(2, 3, A)
>>> CVP.babai(A, (292633475057909760, 256, 256))
(292633475057909760, 296, 405)

"""
A = IntegerMatrix(B.nrows + 1, B.ncols + 1)
for i in range(B.nrows):
Expand All @@ -59,12 +66,17 @@ def babai(B, t, *args, **kwargs):

LLL.reduction(A, *args, **kwargs) # now call LLL to run Babai

# HACK: LLL might have done some swaps, but it shouldn't have!
for row in range(A.nrows):
if A[row, -1] != 0:
break

v = [0] * len(t)
if A[-1, -1] > 0:
if A[row, -1] > 0:
for i in range(len(t)):
v[i] = t[i] - A[-1][i]
v[i] = t[i] - A[row][i]
else:
for i in range(len(t)):
v[i] = t[i] + A[-1][i]
v[i] = t[i] + A[row][i]

return tuple(v)
Loading