kryptools 1.9.1__tar.gz → 1.9.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {kryptools-1.9.1 → kryptools-1.9.2}/PKG-INFO +1 -1
  2. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/__init__.py +3 -3
  3. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor.py +2 -3
  4. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/lat.py +12 -4
  5. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/lat2.py +1 -11
  6. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools.egg-info/PKG-INFO +1 -1
  7. {kryptools-1.9.1 → kryptools-1.9.2}/pyproject.toml +1 -1
  8. {kryptools-1.9.1 → kryptools-1.9.2}/LICENSE +0 -0
  9. {kryptools-1.9.1 → kryptools-1.9.2}/README.md +0 -0
  10. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/GF2.py +0 -0
  11. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/Zmod.py +0 -0
  12. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/aes.py +0 -0
  13. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/blockcipher.py +0 -0
  14. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/code.py +0 -0
  15. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/conway_polynomials.py +0 -0
  16. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/des.py +0 -0
  17. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/dlp.py +0 -0
  18. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/dlp_bsgs.py +0 -0
  19. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/dlp_ic.py +0 -0
  20. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/dlp_qs.py +0 -0
  21. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/dlp_rho.py +0 -0
  22. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/ec.py +0 -0
  23. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_dix.py +0 -0
  24. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_ecm.py +0 -0
  25. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_fmt.py +0 -0
  26. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_pm1.py +0 -0
  27. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_qs.py +0 -0
  28. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/factor_rho.py +0 -0
  29. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/intfuncs.py +0 -0
  30. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/keccak.py +0 -0
  31. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/la.py +0 -0
  32. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/nt.py +0 -0
  33. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/poly.py +0 -0
  34. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/primes.py +0 -0
  35. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools/sha1.py +0 -0
  36. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools.egg-info/SOURCES.txt +0 -0
  37. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools.egg-info/dependency_links.txt +0 -0
  38. {kryptools-1.9.1 → kryptools-1.9.2}/kryptools.egg-info/top_level.txt +0 -0
  39. {kryptools-1.9.1 → kryptools-1.9.2}/setup.cfg +0 -0
  40. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_GF2.py +0 -0
  41. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_Zmod.py +0 -0
  42. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_aes.py +0 -0
  43. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_code.py +0 -0
  44. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_des.py +0 -0
  45. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_dlog.py +0 -0
  46. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_ec.py +0 -0
  47. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_factor.py +0 -0
  48. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_factor_fmt.py +0 -0
  49. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_factor_pm1.py +0 -0
  50. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_factor_qs.py +0 -0
  51. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_intfuncs.py +0 -0
  52. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_keccak.py +0 -0
  53. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_la.py +0 -0
  54. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_lat.py +0 -0
  55. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_nt.py +0 -0
  56. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_poly.py +0 -0
  57. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_primes.py +0 -0
  58. {kryptools-1.9.1 → kryptools-1.9.2}/tests/test_sha1.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.9.1
3
+ Version: 1.9.2
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  License: MIT
@@ -3,9 +3,9 @@ Implemenation of same basic algorithms used in cryptography.
3
3
  """
4
4
 
5
5
  __author__ = "Gerald Teschl"
6
- __copyright__ = "Copyright 2024-2025, Gerald Teschl"
6
+ __copyright__ = "Copyright 2024-2026, Gerald Teschl"
7
7
  __license__ = "MIT License"
8
- __version__ = "1.9.1"
8
+ __version__ = "1.9.2"
9
9
  __email__ = "Gerald.Teschl@univie.ac.at"
10
10
 
11
11
  from .nt import egcd, cf, convergents, legendre_symbol, jacobi_symbol, sqrt_mod, euler_phi, carmichael_lambda, moebius_mu, is_carmichael_number, order, crt
@@ -16,7 +16,7 @@ from .dlp import dlog
16
16
  from .ec import EC_Weierstrass
17
17
  from .la import Matrix, zeros, eye, circulant, BinaryMatrix
18
18
  from .lat import Lattice, random_unimodular_matrix
19
- from .lat2 import q_ary_lattice, gram_det, hadamard_ratio, hermite_nf, gram_schmidt, babai_round_cvp, babai_round_bnd, babai_plane_cvp, babai_plane_bnd, lll, svp, cvp, sis, isis, sis_search, isis_search
19
+ from .lat2 import q_ary_lattice, gram_det, hadamard_ratio, hermite_nf, gram_schmidt, babai_round_cvp, babai_plane_cvp, babai_plane_bnd, lll, svp, cvp, sis, isis, sis_search, isis_search
20
20
  from .poly import Poly, PolyBinMult, lagrange_interpolation
21
21
  from .Zmod import Zmod
22
22
  from .GF2 import GF2, GF2_aes, GF2_miniaes, GF2_ghash
@@ -209,8 +209,7 @@ def divisors(n:int, proper:bool = False) -> int:
209
209
  i = 0
210
210
  d = prod(primes[i] ** exponents[i] for i in range(nprimes))
211
211
  if d == n:
212
- if proper:
213
- return divisor_list
214
- divisor_list.append(n)
212
+ if not proper:
213
+ divisor_list.append(n)
215
214
  return divisor_list
216
215
  divisor_list.append(d)
@@ -205,7 +205,7 @@ class Lattice():
205
205
  print(f"Total number of steps: {steps}")
206
206
 
207
207
  def hnf(self) -> None:
208
- "Transform the basis into Hermite normal form.."
208
+ "Transform the basis into Hermite normal form."
209
209
  if self.Uhnf is None:
210
210
  self.Uhnf = self.basis().hnf().matrix
211
211
  self.Us = None
@@ -237,7 +237,7 @@ class Lattice():
237
237
  self.N[j] = Fraction(self.N[j])
238
238
  self.Us_end = end + 1
239
239
 
240
- def size_reduce(self, j: int) -> bool:
240
+ def size_reduce_one(self, j: int) -> bool:
241
241
  "Size reduction at index `j`."
242
242
  self.gsd(j)
243
243
  reduced = False
@@ -251,6 +251,14 @@ class Lattice():
251
251
  self.M[j][k] -= r * self.M[i][k]
252
252
  return reduced
253
253
 
254
+ def size_reduce(self) -> bool:
255
+ "Size reduction at all indices."
256
+ reduced = False
257
+ for j in range(self.len):
258
+ if self.size_reduce_one(j):
259
+ reduced = True
260
+ return reduced
261
+
254
262
  def swap(self, j:int, newN1 = None) -> None:
255
263
  "Swap columns j and j-1 and update the Gram-Schmidt decomposition."
256
264
  self.U[j - 1], self.U[j] = self.U[j], self.U[j - 1]
@@ -296,7 +304,7 @@ class Lattice():
296
304
  steps = 0
297
305
  while j < self.len:
298
306
  steps += 1
299
- if self.size_reduce(j) and verbose:
307
+ if self.size_reduce_one(j) and verbose:
300
308
  print(f"Reduced basis vector {j}")
301
309
  if all(self.U[j][l] == 0 for l in range(self.dim)):
302
310
  if verbose:
@@ -372,7 +380,7 @@ class Lattice():
372
380
  c = lat.svp_enum(coordinates = True, reduce = False)
373
381
  uu = lat.basis() * c
374
382
  if uu.norm2() == lat.norm2(lat.U[0]):
375
- if self.size_reduce(start):
383
+ if self.size_reduce_one(start):
376
384
  changed = True
377
385
  continue
378
386
  # the new vector is shorter
@@ -2,7 +2,7 @@
2
2
  Lattice tools 2
3
3
  """
4
4
 
5
- from math import prod, floor, inf
5
+ from math import prod, inf
6
6
  from itertools import product
7
7
  from .la import Matrix, eye
8
8
  from .lat import Lattice
@@ -12,7 +12,6 @@ def hermite_nf(M: Matrix) -> Matrix:
12
12
  "Compute the Hermite normal form of a matrix M."
13
13
  return M.hnf()
14
14
 
15
-
16
15
  def gram_schmidt(U: Matrix, drop_dependent: bool = True) -> (Matrix, Matrix):
17
16
  "Compute the Gram-Schmidt orthogonalization of the column vectors of a matrix M."
18
17
  M = U.eye(U.cols)
@@ -36,30 +35,22 @@ def gram_schmidt(U: Matrix, drop_dependent: bool = True) -> (Matrix, Matrix):
36
35
  M = M[:-jj,:-jj]
37
36
  return Us, M
38
37
 
39
-
40
38
  def gram_det(U: Matrix) -> float:
41
39
  "Compute the Gram determinant of a matrix."
42
40
  Us = gram_schmidt(U, drop_dependent = False)[0]
43
41
  return prod([Us[:, i].norm() for i in range(U.rows)])
44
42
 
45
-
46
43
  def hadamard_ratio(M: Matrix) -> float:
47
44
  "Compute the Hadamard ratio of a matrix."
48
45
  m = M.rows
49
46
  return (gram_det(M) / prod([M[:, i].norm() for i in range(m)])) ** (1 / m)
50
47
 
51
-
52
48
  def babai_round_cvp(x: Matrix, U: Matrix) -> Matrix:
53
49
  "Babai's rounding algorithm for approximately solving the CVP."
54
50
  s = U.inv() * x
55
51
  k = s.applyfunc(round)
56
52
  return U * k
57
53
 
58
- def babai_round_bnd(U: Matrix) -> float:
59
- "Bound for Babai's rounding algorithm for solving the CVPwith respect to the sup norm."
60
- return floor(1 / (2 * max(U.inv()[i, :].norm(1) for i in range(U.rows))))
61
-
62
-
63
54
  def babai_plane_cvp(x: Matrix, U: Matrix) -> Matrix:
64
55
  "Babai's closest plane algorithm for approximately solving the CVP."
65
56
  Us = gram_schmidt(U)[0]
@@ -68,7 +59,6 @@ def babai_plane_cvp(x: Matrix, U: Matrix) -> Matrix:
68
59
  y = y - round(y.dot(Us[:, k]) / Us[:, k].norm2()) * U[:, k]
69
60
  return (x - y).applyfunc(round)
70
61
 
71
-
72
62
  def babai_plane_bnd(U: Matrix, p=2) -> float:
73
63
  "Bound for Babai's closest plane algorithm for solving the CVP with respect to the Euclidean norm (p=2) or sup norm (p=inf)."
74
64
  Us = gram_schmidt(U)[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.9.1
3
+ Version: 1.9.2
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kryptools"
3
- version = "1.9.1"
3
+ version = "1.9.2"
4
4
  authors = [
5
5
  { name="Gerald Teschl", email="gerald.teschl@univie.ac.at" },
6
6
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes