Skip to content

Commit 6442ebb

Browse files
committed
Small bug fix
1 parent e77bfca commit 6442ebb

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎kryptools/lat.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def compute_weights(self, start: int = 0) -> None:
136136
def weight_reduce(self) -> bool:
137137
"Pairwise reducte all weights of the basis vectors."
138138
reduced = False
139-
for j in range(1, self.len):
139+
j = 1
140+
while j < self.len:
140141
for i in range(j - 1, -1, -1):
141142
r = round(self.Mu[j][i])
142143
if not r:
@@ -150,13 +151,15 @@ def weight_reduce(self) -> bool:
150151
Nuj = self.norm2(self.U[j])
151152
if not Nuj:
152153
self.delete_vector(j)
153-
continue
154+
break
154155
if self.fraction:
155156
Nuj = Fraction(Nuj)
156157
for k in range(self.len):
157158
if j != k:
158159
self.Mu[k][j] = (self.Nu[j] * self.Mu[k][j] - r * self.Nu[i] * self.Mu[k][i]) / Nuj
159160
self.Nu[j] = Nuj
161+
else:
162+
j += 1
160163
return reduced
161164

162165
def hermite(self) -> None:

‎kryptools/lat2.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
from math import prod, floor, inf
66
from itertools import product
7-
from random import choice, sample
8-
from .la import Matrix, eye, zeros
7+
from .la import Matrix, eye
98
from .lat import Lattice
109

1110

@@ -78,7 +77,7 @@ def babai_plane_bnd(U: Matrix, p=2) -> float:
7877
def lll(V: Matrix, delta: float = 0.75, sort: bool = True) -> Matrix:
7978
"LLL algorithm for lattice reduction."
8079
lat = Lattice(V)
81-
lat.lll()
80+
lat.lll(delta = delta)
8281
if sort:
8382
lat.sort()
8483
return lat.basis()

0 commit comments

Comments
 (0)