kryptools 0.7__tar.gz → 0.8__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 (28) hide show
  1. {kryptools-0.7 → kryptools-0.8}/PKG-INFO +2 -2
  2. {kryptools-0.7 → kryptools-0.8}/README.md +1 -1
  3. {kryptools-0.7 → kryptools-0.8}/kryptools/factor.py +1 -1
  4. {kryptools-0.7 → kryptools-0.8}/kryptools/factor_ecm.py +3 -3
  5. {kryptools-0.7 → kryptools-0.8}/kryptools/la.py +3 -3
  6. {kryptools-0.7 → kryptools-0.8}/kryptools/poly.py +12 -7
  7. {kryptools-0.7 → kryptools-0.8}/kryptools.egg-info/PKG-INFO +2 -2
  8. {kryptools-0.7 → kryptools-0.8}/pyproject.toml +1 -1
  9. {kryptools-0.7 → kryptools-0.8}/LICENSE +0 -0
  10. {kryptools-0.7 → kryptools-0.8}/kryptools/Zmod.py +0 -0
  11. {kryptools-0.7 → kryptools-0.8}/kryptools/__init__.py +0 -0
  12. {kryptools-0.7 → kryptools-0.8}/kryptools/dlp.py +0 -0
  13. {kryptools-0.7 → kryptools-0.8}/kryptools/dlp_bsgs.py +0 -0
  14. {kryptools-0.7 → kryptools-0.8}/kryptools/dlp_ic.py +0 -0
  15. {kryptools-0.7 → kryptools-0.8}/kryptools/dlp_qs.py +0 -0
  16. {kryptools-0.7 → kryptools-0.8}/kryptools/dlp_rho.py +0 -0
  17. {kryptools-0.7 → kryptools-0.8}/kryptools/ec.py +0 -0
  18. {kryptools-0.7 → kryptools-0.8}/kryptools/factor_dix.py +0 -0
  19. {kryptools-0.7 → kryptools-0.8}/kryptools/factor_fmt.py +0 -0
  20. {kryptools-0.7 → kryptools-0.8}/kryptools/factor_pm1.py +0 -0
  21. {kryptools-0.7 → kryptools-0.8}/kryptools/factor_qs.py +0 -0
  22. {kryptools-0.7 → kryptools-0.8}/kryptools/lat.py +0 -0
  23. {kryptools-0.7 → kryptools-0.8}/kryptools/nt.py +0 -0
  24. {kryptools-0.7 → kryptools-0.8}/kryptools/primes.py +0 -0
  25. {kryptools-0.7 → kryptools-0.8}/kryptools.egg-info/SOURCES.txt +0 -0
  26. {kryptools-0.7 → kryptools-0.8}/kryptools.egg-info/dependency_links.txt +0 -0
  27. {kryptools-0.7 → kryptools-0.8}/kryptools.egg-info/top_level.txt +0 -0
  28. {kryptools-0.7 → kryptools-0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.7
3
+ Version: 0.8
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  Project-URL: Homepage, https://github.com/teschlg/kryptools
@@ -27,7 +27,7 @@ The tools contained are:
27
27
  * number theory: sqrt modulo primes, crt, continued fractions, etc.
28
28
  * primes: Sieve of Erathostenes, primality tests
29
29
  * solvers for discrete logarithms (naive, Pollard rho, Shanks baby step/giant step, index calculus, quadratic sieve)
30
- * integer factorization (Fermat, Pollard p-1, Lentra's ECM, Dixon, basic quadratic sieve)
30
+ * integer factorization (Fermat, Pollard p-1, Lenstra's ECM, Dixon, basic quadratic sieve)
31
31
  * linear algebra: Hermite normal form, Gram-Schmidt
32
32
  * lattices: Babai rounding/nearest plane, lattice reduction
33
33
 
@@ -12,7 +12,7 @@ The tools contained are:
12
12
  * number theory: sqrt modulo primes, crt, continued fractions, etc.
13
13
  * primes: Sieve of Erathostenes, primality tests
14
14
  * solvers for discrete logarithms (naive, Pollard rho, Shanks baby step/giant step, index calculus, quadratic sieve)
15
- * integer factorization (Fermat, Pollard p-1, Lentra's ECM, Dixon, basic quadratic sieve)
15
+ * integer factorization (Fermat, Pollard p-1, Lenstra's ECM, Dixon, basic quadratic sieve)
16
16
  * linear algebra: Hermite normal form, Gram-Schmidt
17
17
  * lattices: Babai rounding/nearest plane, lattice reduction
18
18
 
@@ -88,7 +88,7 @@ def factorint(n: int, verbose: int = 0) -> list:
88
88
  D = isqrt(B2)
89
89
  primes = sieve_eratosthenes(B1 - 1 + ((B2 - B1 + 1) // (2 * D) + 1) * 2 * D)
90
90
  pm1_parameters = _pm1_parameters(10 * B1, B2, primes = primes)
91
- ecm_parameters = tuple([num_curves] + list(_ecm_parameters(B1, B2, D, primes = primes)))
91
+ ecm_parameters = tuple([B1, B2, num_curves] + list(_ecm_parameters(B1, B2, D, primes = primes)))
92
92
 
93
93
  methods = {_factor_fermat: "fm", factor_pm1: "pm1", factor_ecm: "ecm"} #, factor_qs: "qs"}
94
94
  while remaining_factors:
@@ -57,7 +57,7 @@ def _ecm_parameters(B1: int, B2: int = None, D: int = None, primes: tuple = None
57
57
  else:
58
58
  B2 += B2 & 1
59
59
  if not D:
60
- D = isqrt(B2)
60
+ D = min(isqrt(B2), B1 // 2 - 1)
61
61
  if not primes:
62
62
  primes = sieve_eratosthenes(B1 - 1 + ((B2 - B1 + 1) // (2 * D) + 1) * 2 * D)
63
63
 
@@ -71,7 +71,7 @@ def _ecm_parameters(B1: int, B2: int = None, D: int = None, primes: tuple = None
71
71
  r = B1 - 1
72
72
  stage_two_deltas[r] = []
73
73
  for p in primes:
74
- if p <= r:
74
+ if p < r:
75
75
  continue
76
76
  if p <= r + 2 * D:
77
77
  stage_two_deltas[r].append((p - r) // 2)
@@ -88,7 +88,7 @@ def factor_ecm(n: int, B1: int = 11000, B2: int = 1900000, curves: int = 74, ecm
88
88
  "Factors a number n using Lentsta's ECM method."
89
89
 
90
90
  if ecm_parameters:
91
- curves, D, stage_one, stage_two_deltas = ecm_parameters
91
+ B1, B2, curves, D, stage_one, stage_two_deltas = ecm_parameters
92
92
  else:
93
93
  D, stage_one, stage_two_deltas = _ecm_parameters(B1, B2)
94
94
 
@@ -268,7 +268,7 @@ class Matrix:
268
268
  zero = 0 * self[0]
269
269
  except:
270
270
  zero = 0
271
- return Matrix([[ zero for j in range(n)] for i in range(m) ])
271
+ return Matrix([[ zero for j in range(n) ] for i in range(m) ])
272
272
 
273
273
  def eye(self, m: int = None, n: int = None):
274
274
  "Returns an identity matrix of the same dimension"
@@ -288,11 +288,11 @@ class Matrix:
288
288
  return Matrix([[ delta(i, j) for j in range(n) ] for i in range(m) ])
289
289
 
290
290
 
291
- def zeros(m: int, n: int = None) -> "Matrix":
291
+ def zeros(m: int, n: int = None, zero = 0) -> "Matrix":
292
292
  "Returns a zero matrix of the given dimension"
293
293
  if not n:
294
294
  n = m
295
- return Matrix([[ 0 for j in range(n)] for i in range(m) ])
295
+ return Matrix([[ zero for j in range(n) ] for i in range(m) ])
296
296
 
297
297
  def eye(m:int, n: int = None) -> "Matrix":
298
298
  "Returns an identity matrix of the given dimension"
@@ -10,7 +10,7 @@ class Poly:
10
10
 
11
11
  Example:
12
12
 
13
- To define a polynomial as alist of coefficients use
13
+ To define a polynomial as a list of coefficients use
14
14
  >>> Poly([1, 2, 3])
15
15
  3 x^2 + 2 x + 1
16
16
  """
@@ -203,21 +203,26 @@ class Poly:
203
203
  raise NotImplementedError("Cannot invert polynomials without modulus.")
204
204
  return other * self.inv()
205
205
 
206
- def __pow__(self, i: int) -> "Poly":
207
- if not isinstance(i, int):
206
+ def __pow__(self, j: int) -> "Poly":
207
+ if not isinstance(j, int):
208
208
  return NotImplemented
209
209
  zero = 0 * self.coeff[0]
210
210
  one = zero + 1
211
211
  res = self.__class__([one], modulus=self.modulus)
212
- if i < 0:
212
+ if j < 0:
213
213
  if not self.modulus:
214
214
  raise NotImplementedError("Cannot divide polynomials without modulus.")
215
215
  tmp = self.inv()
216
- i *= -1
216
+ j *= -1
217
217
  else:
218
218
  tmp = self
219
- for _ in range(i):
220
- res *= tmp
219
+ while j > 0:
220
+ # If j is odd, multiply
221
+ if j & 1:
222
+ res *= tmp
223
+ # Now square
224
+ j = j >> 1 # j= j//2
225
+ tmp *= tmp
221
226
  return res
222
227
 
223
228
  def max(self) -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.7
3
+ Version: 0.8
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  Project-URL: Homepage, https://github.com/teschlg/kryptools
@@ -27,7 +27,7 @@ The tools contained are:
27
27
  * number theory: sqrt modulo primes, crt, continued fractions, etc.
28
28
  * primes: Sieve of Erathostenes, primality tests
29
29
  * solvers for discrete logarithms (naive, Pollard rho, Shanks baby step/giant step, index calculus, quadratic sieve)
30
- * integer factorization (Fermat, Pollard p-1, Lentra's ECM, Dixon, basic quadratic sieve)
30
+ * integer factorization (Fermat, Pollard p-1, Lenstra's ECM, Dixon, basic quadratic sieve)
31
31
  * linear algebra: Hermite normal form, Gram-Schmidt
32
32
  * lattices: Babai rounding/nearest plane, lattice reduction
33
33
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kryptools"
3
- version = "0.7"
3
+ version = "0.8"
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