kryptools 1.9__tar.gz → 1.9.1__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 → kryptools-1.9.1}/PKG-INFO +3 -3
  2. {kryptools-1.9 → kryptools-1.9.1}/README.md +2 -2
  3. {kryptools-1.9 → kryptools-1.9.1}/kryptools/__init__.py +1 -1
  4. {kryptools-1.9 → kryptools-1.9.1}/kryptools/la.py +1 -1
  5. {kryptools-1.9 → kryptools-1.9.1}/kryptools/poly.py +11 -5
  6. {kryptools-1.9 → kryptools-1.9.1}/kryptools.egg-info/PKG-INFO +3 -3
  7. {kryptools-1.9 → kryptools-1.9.1}/pyproject.toml +1 -1
  8. {kryptools-1.9 → kryptools-1.9.1}/tests/test_poly.py +14 -7
  9. {kryptools-1.9 → kryptools-1.9.1}/LICENSE +0 -0
  10. {kryptools-1.9 → kryptools-1.9.1}/kryptools/GF2.py +0 -0
  11. {kryptools-1.9 → kryptools-1.9.1}/kryptools/Zmod.py +0 -0
  12. {kryptools-1.9 → kryptools-1.9.1}/kryptools/aes.py +0 -0
  13. {kryptools-1.9 → kryptools-1.9.1}/kryptools/blockcipher.py +0 -0
  14. {kryptools-1.9 → kryptools-1.9.1}/kryptools/code.py +0 -0
  15. {kryptools-1.9 → kryptools-1.9.1}/kryptools/conway_polynomials.py +0 -0
  16. {kryptools-1.9 → kryptools-1.9.1}/kryptools/des.py +0 -0
  17. {kryptools-1.9 → kryptools-1.9.1}/kryptools/dlp.py +0 -0
  18. {kryptools-1.9 → kryptools-1.9.1}/kryptools/dlp_bsgs.py +0 -0
  19. {kryptools-1.9 → kryptools-1.9.1}/kryptools/dlp_ic.py +0 -0
  20. {kryptools-1.9 → kryptools-1.9.1}/kryptools/dlp_qs.py +0 -0
  21. {kryptools-1.9 → kryptools-1.9.1}/kryptools/dlp_rho.py +0 -0
  22. {kryptools-1.9 → kryptools-1.9.1}/kryptools/ec.py +0 -0
  23. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor.py +0 -0
  24. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_dix.py +0 -0
  25. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_ecm.py +0 -0
  26. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_fmt.py +0 -0
  27. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_pm1.py +0 -0
  28. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_qs.py +0 -0
  29. {kryptools-1.9 → kryptools-1.9.1}/kryptools/factor_rho.py +0 -0
  30. {kryptools-1.9 → kryptools-1.9.1}/kryptools/intfuncs.py +0 -0
  31. {kryptools-1.9 → kryptools-1.9.1}/kryptools/keccak.py +0 -0
  32. {kryptools-1.9 → kryptools-1.9.1}/kryptools/lat.py +0 -0
  33. {kryptools-1.9 → kryptools-1.9.1}/kryptools/lat2.py +0 -0
  34. {kryptools-1.9 → kryptools-1.9.1}/kryptools/nt.py +0 -0
  35. {kryptools-1.9 → kryptools-1.9.1}/kryptools/primes.py +0 -0
  36. {kryptools-1.9 → kryptools-1.9.1}/kryptools/sha1.py +0 -0
  37. {kryptools-1.9 → kryptools-1.9.1}/kryptools.egg-info/SOURCES.txt +0 -0
  38. {kryptools-1.9 → kryptools-1.9.1}/kryptools.egg-info/dependency_links.txt +0 -0
  39. {kryptools-1.9 → kryptools-1.9.1}/kryptools.egg-info/top_level.txt +0 -0
  40. {kryptools-1.9 → kryptools-1.9.1}/setup.cfg +0 -0
  41. {kryptools-1.9 → kryptools-1.9.1}/tests/test_GF2.py +0 -0
  42. {kryptools-1.9 → kryptools-1.9.1}/tests/test_Zmod.py +0 -0
  43. {kryptools-1.9 → kryptools-1.9.1}/tests/test_aes.py +0 -0
  44. {kryptools-1.9 → kryptools-1.9.1}/tests/test_code.py +0 -0
  45. {kryptools-1.9 → kryptools-1.9.1}/tests/test_des.py +0 -0
  46. {kryptools-1.9 → kryptools-1.9.1}/tests/test_dlog.py +0 -0
  47. {kryptools-1.9 → kryptools-1.9.1}/tests/test_ec.py +0 -0
  48. {kryptools-1.9 → kryptools-1.9.1}/tests/test_factor.py +0 -0
  49. {kryptools-1.9 → kryptools-1.9.1}/tests/test_factor_fmt.py +0 -0
  50. {kryptools-1.9 → kryptools-1.9.1}/tests/test_factor_pm1.py +0 -0
  51. {kryptools-1.9 → kryptools-1.9.1}/tests/test_factor_qs.py +0 -0
  52. {kryptools-1.9 → kryptools-1.9.1}/tests/test_intfuncs.py +0 -0
  53. {kryptools-1.9 → kryptools-1.9.1}/tests/test_keccak.py +0 -0
  54. {kryptools-1.9 → kryptools-1.9.1}/tests/test_la.py +0 -0
  55. {kryptools-1.9 → kryptools-1.9.1}/tests/test_lat.py +0 -0
  56. {kryptools-1.9 → kryptools-1.9.1}/tests/test_nt.py +0 -0
  57. {kryptools-1.9 → kryptools-1.9.1}/tests/test_primes.py +0 -0
  58. {kryptools-1.9 → kryptools-1.9.1}/tests/test_sha1.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.9
3
+ Version: 1.9.1
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
@@ -44,12 +44,12 @@ The tools contained are:
44
44
  * integer factorization (Fermat, Pollard p-1, Pollard rho, Lenstra's ECM, Dixon, basic quadratic sieve)
45
45
  * elliptic curves (Weierstrass form), group operations, order, discrete logarithms
46
46
  * linear algebra: Hermite normal form, Smith normal form, Gram-Schmidt
47
- * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovaz, BKZ), SIS, ISIS, LWE
47
+ * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovasz, BKZ), SIS, ISIS, LWE
48
48
  * linear codes: Hamming distance, left standard form, parity check matrix
49
49
 
50
50
  * Matrix: a class for Matrices (inverse, det, reduced echelon form, kernel, solving linear systems, etc.)
51
51
  * BinaryMatrix: a class for Matrices with binary entries (for much faster row operations)
52
- * Lattice: a class for lattices (SVP, CPV, LLL, BKZ, HKZ)
52
+ * Lattice: a class for lattices (SVP, CVP, LLL, BKZ, HKZ)
53
53
  * Poly: a class for polynomials (division, modulo, factoring and irreducibility test over finite fields, Lagrange interpolation)
54
54
  * Zmod: a class for the ring of integers modulo an integer
55
55
  * GF2: a class for Galois fields GF(2^n)
@@ -26,12 +26,12 @@ The tools contained are:
26
26
  * integer factorization (Fermat, Pollard p-1, Pollard rho, Lenstra's ECM, Dixon, basic quadratic sieve)
27
27
  * elliptic curves (Weierstrass form), group operations, order, discrete logarithms
28
28
  * linear algebra: Hermite normal form, Smith normal form, Gram-Schmidt
29
- * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovaz, BKZ), SIS, ISIS, LWE
29
+ * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovasz, BKZ), SIS, ISIS, LWE
30
30
  * linear codes: Hamming distance, left standard form, parity check matrix
31
31
 
32
32
  * Matrix: a class for Matrices (inverse, det, reduced echelon form, kernel, solving linear systems, etc.)
33
33
  * BinaryMatrix: a class for Matrices with binary entries (for much faster row operations)
34
- * Lattice: a class for lattices (SVP, CPV, LLL, BKZ, HKZ)
34
+ * Lattice: a class for lattices (SVP, CVP, LLL, BKZ, HKZ)
35
35
  * Poly: a class for polynomials (division, modulo, factoring and irreducibility test over finite fields, Lagrange interpolation)
36
36
  * Zmod: a class for the ring of integers modulo an integer
37
37
  * GF2: a class for Galois fields GF(2^n)
@@ -5,7 +5,7 @@ Implemenation of same basic algorithms used in cryptography.
5
5
  __author__ = "Gerald Teschl"
6
6
  __copyright__ = "Copyright 2024-2025, Gerald Teschl"
7
7
  __license__ = "MIT License"
8
- __version__ = "1.9"
8
+ __version__ = "1.9.1"
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
@@ -1079,7 +1079,7 @@ class BinaryMatrix:
1079
1079
  n = 0
1080
1080
  for bit in b:
1081
1081
  n <<= 1
1082
- n += bit
1082
+ n += int(bit)
1083
1083
  return n
1084
1084
 
1085
1085
  def bitmatrix(self) -> list[list]:
@@ -142,6 +142,8 @@ class Poly:
142
142
  except: # pylint: disable=W0702
143
143
  pass
144
144
  try:
145
+ if hasattr(s, "ring") and hasattr(s.ring, "sharp") and s.ring.sharp:
146
+ s = s.sharp()
145
147
  if plus and s < 0:
146
148
  tmp += " - " + str(-s)
147
149
  if i != 0:
@@ -225,9 +227,11 @@ class Poly:
225
227
  return self.__class__(list(map(func, self.coeff)), modulus = self.modulus, cyclic = self.cyclic)
226
228
 
227
229
  def _check_type(self, other):
230
+ "Check if self and other can be added/multiplied."
228
231
  return isinstance(other, int) or (isinstance(other, Number) and isinstance(self.coeff[0], Number)) or type(other) == type(self.coeff[0]) # pylint: disable=C0123
229
232
 
230
233
  def _guess_ring(self):
234
+ "Try to guess from which the ring the coefficients are."
231
235
  zero = 0 * self.coeff[0]
232
236
  one = zero**0
233
237
  if hasattr(zero, "ring"):
@@ -241,6 +245,7 @@ class Poly:
241
245
  return zero, one, ring
242
246
 
243
247
  def _guess_field(self):
248
+ "Try to guess from which field the coefficients are."
244
249
  zero, one, field = self._guess_ring()
245
250
  if not field:
246
251
  raise ValueError(
@@ -251,7 +256,7 @@ class Poly:
251
256
  if not field.is_field():
252
257
  raise ValueError(
253
258
  "The polynomial does not seem to be over a finite field.")
254
- else: # G2 or galois
259
+ else: # GF2 or galois
255
260
  p = field.characteristic
256
261
  q = field.order
257
262
  return field, zero, one, q, p
@@ -293,13 +298,13 @@ class Poly:
293
298
  return (- self) + other
294
299
 
295
300
  def __mul__(self, other: "Poly") -> "Poly":
301
+ zero = 0 * self.coeff[0]
296
302
  if not isinstance(other, self.__class__):
297
303
  if self._check_type(other):
298
304
  if not other:
299
- return self.__class__([other], modulus = self.modulus, cyclic = self.cyclic, check = False)
305
+ return self.__class__([zero], modulus = self.modulus, cyclic = self.cyclic, check = False)
300
306
  return self.__class__([other * s for s in self.coeff], modulus = self.modulus, cyclic = self.cyclic, check = False)
301
307
  return NotImplemented
302
- zero = 0 * self.coeff[0]
303
308
  ls, lo = len(self.coeff), len(other.coeff)
304
309
  if self.cyclic or other.cyclic:
305
310
  if self.cyclic:
@@ -319,8 +324,8 @@ class Poly:
319
324
  if cyclic > 0:
320
325
  coeff = [ sum( (selfc[j] * otherc[(k-j) % n] for j in range(ls)), start = zero) for k in range(n)]
321
326
  else:
322
- coeff = [ sum( (selfc[j] * otherc[(k-j) % n] for j in range(min(k,ls))), start = zero) -
323
- sum( (selfc[j] * otherc[(k-j) % n] for j in range(k,ls)), start = zero) for k in range(n)]
327
+ coeff = [ sum( (selfc[j] * otherc[k - j] for j in range(min(k+1,ls))), start = zero) -
328
+ sum( (selfc[j] * otherc[n + k - j] for j in range(k+1,ls)), start = zero) for k in range(n)]
324
329
  ret = self.__class__(coeff, modulus = modulus, cyclic = cyclic, check = False)
325
330
  ret.strip()
326
331
  return ret
@@ -521,6 +526,7 @@ class Poly:
521
526
  if r0.degree() != 0:
522
527
  raise ValueError(f"{self} is not invertible mod {other}.")
523
528
  y0.modulus = self.modulus
529
+ y0.cyclic = self.cyclic
524
530
  if r0.coeff[0] == one:
525
531
  return y0
526
532
  return y0 / r0.coeff[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.9
3
+ Version: 1.9.1
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
@@ -44,12 +44,12 @@ The tools contained are:
44
44
  * integer factorization (Fermat, Pollard p-1, Pollard rho, Lenstra's ECM, Dixon, basic quadratic sieve)
45
45
  * elliptic curves (Weierstrass form), group operations, order, discrete logarithms
46
46
  * linear algebra: Hermite normal form, Smith normal form, Gram-Schmidt
47
- * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovaz, BKZ), SIS, ISIS, LWE
47
+ * lattices: Hadamard ratio, Babai rounding/nearest plane algorithm, lattice reduction (Hermite, Lenstra-Lenstra-Lovasz, BKZ), SIS, ISIS, LWE
48
48
  * linear codes: Hamming distance, left standard form, parity check matrix
49
49
 
50
50
  * Matrix: a class for Matrices (inverse, det, reduced echelon form, kernel, solving linear systems, etc.)
51
51
  * BinaryMatrix: a class for Matrices with binary entries (for much faster row operations)
52
- * Lattice: a class for lattices (SVP, CPV, LLL, BKZ, HKZ)
52
+ * Lattice: a class for lattices (SVP, CVP, LLL, BKZ, HKZ)
53
53
  * Poly: a class for polynomials (division, modulo, factoring and irreducibility test over finite fields, Lagrange interpolation)
54
54
  * Zmod: a class for the ring of integers modulo an integer
55
55
  * GF2: a class for Galois fields GF(2^n)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kryptools"
3
- version = "1.9"
3
+ version = "1.9.1"
4
4
  authors = [
5
5
  { name="Gerald Teschl", email="gerald.teschl@univie.ac.at" },
6
6
  ]
@@ -21,17 +21,24 @@ def test_Poly():
21
21
  assert q * p == p.gcd(q) * p.lcm(q)
22
22
  assert d * p + m == q
23
23
  for _ in range(num_tests):
24
- p = Poly([randint(0,100) for _ in range(10)])
25
- q = Poly([randint(0,100) for _ in range(12)])
26
- x = randint(0,100)
24
+ p = Poly([randint(-100,100) for _ in range(10)])
25
+ q = Poly([randint(-100,100) for _ in range(12)])
26
+ x = randint(-100,100)
27
27
  assert p(x) == sum((c * x**j for j, c in enumerate(p.coeff)), start=0)
28
28
  assert (p + q)(x) == p(x) + q(x)
29
29
  assert (p - q)(x) == p(x) - q(x)
30
30
  assert (p*q)(x) == p(x) * q(x)
31
- modulus = [-1] + 7 * [0] + [1]
32
- p = [ randint(0,9) for _ in range(8) ]
33
- q = [ randint(0,9) for _ in range(8) ]
34
- assert list(circulant(p) * Matrix(q)) == (Poly(p, modulus = modulus) * Poly(q, modulus = modulus)).coeff
31
+ n = 8
32
+ modulus = [-1] + (n-1) * [0] + [1]
33
+ for _ in range(num_tests):
34
+ p = [ randint(-9,9) for _ in range(n) ]
35
+ q = [ randint(-9,9) for _ in range(n) ]
36
+ assert list(circulant(p) * Matrix(q)) == (Poly(p, modulus = modulus) * Poly(q, modulus = modulus)).coeff
37
+ modulus = [1] + (n-1) * [0] + [1]
38
+ for _ in range(num_tests):
39
+ p = [ randint(-9,9) for _ in range(n) ]
40
+ q = [ randint(-9,9) for _ in range(n) ]
41
+ assert Poly(p) * Poly(q) % Poly(modulus) == (Poly(p, modulus = modulus) * Poly(q, modulus = modulus))
35
42
  gf = Zmod(5)
36
43
  p = Poly([2, 0, 2], ring = gf)
37
44
  q = Poly([1, 2, 3, 4], ring = gf)
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
File without changes
File without changes
File without changes
File without changes
File without changes