From cb77b7c7cb744e1029a6ebd08b348dd7b1a751e2 Mon Sep 17 00:00:00 2001 From: blupper <33233478+TheBlupper@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:12:37 +0200 Subject: [PATCH 1/4] Fix norm calculation --- src/fpylll/algorithms/babai.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/fpylll/algorithms/babai.py b/src/fpylll/algorithms/babai.py index b7942d86..5dd267d5 100644 --- a/src/fpylll/algorithms/babai.py +++ b/src/fpylll/algorithms/babai.py @@ -8,10 +8,10 @@ """ from fpylll import IntegerMatrix, LLL -from math import ceil +from math import isqrt -def babai(B, t): +def babai(B, t, *args, **kwargs): """ Run Babai's Nearest Plane algorithm by running LLL. @@ -46,13 +46,14 @@ def babai(B, t): A[i, j] = B[i, j] # make sure the input is LLL reduced before reading the norm of the last vector - LLL.reduction(A) + LLL.reduction(A, *args, **kwargs) # zero vector at the end A.swap_rows(0, B.nrows) for j in range(B.ncols): A[-1, j] = t[j] - A[-1, -1] = ceil(A[-2].norm()) + # precise norm + A[-1, -1] = isqrt(sum(x**2 for x in A[-2])) + 1 LLL.reduction(A) # now call LLL to run Babai From 0cf1973366483aef17bab6a10f00ca7933c52e7e Mon Sep 17 00:00:00 2001 From: blupper <33233478+TheBlupper@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:13:21 +0200 Subject: [PATCH 2/4] Pass on arguments to LLL.reduction --- src/fpylll/algorithms/babai.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fpylll/algorithms/babai.py b/src/fpylll/algorithms/babai.py index 5dd267d5..5b41a7b3 100644 --- a/src/fpylll/algorithms/babai.py +++ b/src/fpylll/algorithms/babai.py @@ -17,6 +17,8 @@ def babai(B, t, *args, **kwargs): :param B: Input lattice basis. :param target: Target point (∈ ZZ^n) + :param args: Passed onto LLL.reduction + :param kwargs: Passed onto LLL.reduction :returns coordinates of the solution vector: This implementation is more numerically stable compared to the one offered by `MatGSO.babai()`. From e1b32b8278545719f95c20b4e28b6b2f7e89ca2a Mon Sep 17 00:00:00 2001 From: blupper <33233478+TheBlupper@users.noreply.github.com> Date: Thu, 6 Jun 2024 02:17:24 +0200 Subject: [PATCH 3/4] Pass on arguments again --- src/fpylll/algorithms/babai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpylll/algorithms/babai.py b/src/fpylll/algorithms/babai.py index 5b41a7b3..c02263db 100644 --- a/src/fpylll/algorithms/babai.py +++ b/src/fpylll/algorithms/babai.py @@ -57,7 +57,7 @@ def babai(B, t, *args, **kwargs): # precise norm A[-1, -1] = isqrt(sum(x**2 for x in A[-2])) + 1 - LLL.reduction(A) # now call LLL to run Babai + LLL.reduction(A, *args, **kwargs) # now call LLL to run Babai v = [0] * len(t) if A[-1, -1] > 0: From ffe760dc97bc83a68243bac8b9643550e06b80d0 Mon Sep 17 00:00:00 2001 From: blupper <33233478+TheBlupper@users.noreply.github.com> Date: Thu, 6 Jun 2024 11:02:50 +0200 Subject: [PATCH 4/4] Document +1 --- src/fpylll/algorithms/babai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fpylll/algorithms/babai.py b/src/fpylll/algorithms/babai.py index c02263db..9011b27f 100644 --- a/src/fpylll/algorithms/babai.py +++ b/src/fpylll/algorithms/babai.py @@ -54,7 +54,7 @@ def babai(B, t, *args, **kwargs): for j in range(B.ncols): A[-1, j] = t[j] - # precise norm + # precise norm, +1 to make sure it's not too small, too big doesn't matter A[-1, -1] = isqrt(sum(x**2 for x in A[-2])) + 1 LLL.reduction(A, *args, **kwargs) # now call LLL to run Babai