kryptools 0.6__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.6 → kryptools-0.8}/PKG-INFO +2 -2
  2. {kryptools-0.6 → kryptools-0.8}/README.md +1 -1
  3. {kryptools-0.6 → kryptools-0.8}/kryptools/Zmod.py +6 -0
  4. {kryptools-0.6 → kryptools-0.8}/kryptools/factor.py +1 -1
  5. {kryptools-0.6 → kryptools-0.8}/kryptools/factor_ecm.py +3 -3
  6. {kryptools-0.6 → kryptools-0.8}/kryptools/la.py +5 -5
  7. {kryptools-0.6 → kryptools-0.8}/kryptools/poly.py +33 -13
  8. {kryptools-0.6 → kryptools-0.8}/kryptools.egg-info/PKG-INFO +2 -2
  9. {kryptools-0.6 → kryptools-0.8}/pyproject.toml +1 -1
  10. {kryptools-0.6 → kryptools-0.8}/LICENSE +0 -0
  11. {kryptools-0.6 → kryptools-0.8}/kryptools/__init__.py +0 -0
  12. {kryptools-0.6 → kryptools-0.8}/kryptools/dlp.py +0 -0
  13. {kryptools-0.6 → kryptools-0.8}/kryptools/dlp_bsgs.py +0 -0
  14. {kryptools-0.6 → kryptools-0.8}/kryptools/dlp_ic.py +0 -0
  15. {kryptools-0.6 → kryptools-0.8}/kryptools/dlp_qs.py +0 -0
  16. {kryptools-0.6 → kryptools-0.8}/kryptools/dlp_rho.py +0 -0
  17. {kryptools-0.6 → kryptools-0.8}/kryptools/ec.py +0 -0
  18. {kryptools-0.6 → kryptools-0.8}/kryptools/factor_dix.py +0 -0
  19. {kryptools-0.6 → kryptools-0.8}/kryptools/factor_fmt.py +0 -0
  20. {kryptools-0.6 → kryptools-0.8}/kryptools/factor_pm1.py +0 -0
  21. {kryptools-0.6 → kryptools-0.8}/kryptools/factor_qs.py +0 -0
  22. {kryptools-0.6 → kryptools-0.8}/kryptools/lat.py +0 -0
  23. {kryptools-0.6 → kryptools-0.8}/kryptools/nt.py +0 -0
  24. {kryptools-0.6 → kryptools-0.8}/kryptools/primes.py +0 -0
  25. {kryptools-0.6 → kryptools-0.8}/kryptools.egg-info/SOURCES.txt +0 -0
  26. {kryptools-0.6 → kryptools-0.8}/kryptools.egg-info/dependency_links.txt +0 -0
  27. {kryptools-0.6 → kryptools-0.8}/kryptools.egg-info/top_level.txt +0 -0
  28. {kryptools-0.6 → kryptools-0.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.6
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
 
@@ -106,6 +106,9 @@ class ZmodPoint:
106
106
  def __neg__(self) -> "ZmodPoint":
107
107
  return self.__class__(-self.x, self.ring)
108
108
 
109
+ def __pos__(self) -> "ZmodPoint":
110
+ return self
111
+
109
112
  def __sub__(self, other: "ZmodPoint") -> "ZmodPoint":
110
113
  if isinstance(other, self.__class__):
111
114
  if self.ring != other.ring:
@@ -151,6 +154,9 @@ class ZmodPoint:
151
154
  return self.__class__(pow(self.x, scalar, self.ring.n), self.ring)
152
155
  return NotImplemented
153
156
 
157
+ def __abs__(self) -> int:
158
+ return abs(self.sharp())
159
+
154
160
  def sharp(self):
155
161
  "Returns a symmetric (w.r.t. 0) representative."
156
162
  tmp = (self.ring.n - 1) // 2
@@ -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
 
@@ -99,12 +99,12 @@ class Matrix:
99
99
  return self.matrix == other.matrix
100
100
 
101
101
  def map(self, func):
102
- "Apply a function to all elements in place"
102
+ "Apply a function to all elements in place."
103
103
  for row in self.matrix:
104
104
  row[:] = map(func, row)
105
105
 
106
106
  def applyfunc(self, func):
107
- "Apply a function to all elements"
107
+ "Apply a function to all elements."
108
108
  tmp = self[:,:]
109
109
  tmp.map(func)
110
110
  return tmp
@@ -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,17 +10,17 @@ 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
  """
17
17
 
18
18
  def __init__(self, coeff: list, ring = None, modulus: list = None):
19
- for i in range(len(coeff) - 1, 0, -1):
20
- if coeff[i]:
19
+ self.coeff = list(coeff)
20
+ for i in range(len(self.coeff) - 1, 0, -1):
21
+ if self.coeff[i]:
21
22
  break
22
- coeff.pop(i)
23
- self.coeff = coeff
23
+ self.coeff.pop(i)
24
24
  self.modulus = modulus
25
25
  if ring:
26
26
  self.map(ring)
@@ -86,14 +86,18 @@ class Poly:
86
86
  def __bool__(self):
87
87
  return bool(self.degree()) or bool(self.coeff[0])
88
88
 
89
- def degree(self):
89
+ def degree(self) -> int:
90
90
  "Return the degree."
91
91
  return len(self.coeff) - 1
92
92
 
93
93
  def map(self, func):
94
- "Apply a given function to all coefficients."
94
+ "Apply a given function to all coefficients in place."
95
95
  self.coeff = list(map(func, self.coeff))
96
96
 
97
+ def applyfunc(self, func) -> "Poly":
98
+ "Apply a function to all coefficients."
99
+ return self.__class__(list(map(func, self.coeff)), modulus=self.modulus)
100
+
97
101
  def _check_type(self, other):
98
102
  return isinstance(other, int) or (isinstance(other, Number) and isinstance(self.coeff[0], Number)) or type(other) == type(self.coeff[0])
99
103
 
@@ -129,6 +133,9 @@ class Poly:
129
133
  def __neg__(self) -> "Poly":
130
134
  return Poly([-s for s in self.coeff], modulus=self.modulus)
131
135
 
136
+ def __pos__(self) -> "Poly":
137
+ return self
138
+
132
139
  def __sub__(self, other: "Poly") -> "Poly":
133
140
  if not isinstance(other, self.__class__):
134
141
  if self._check_type(other):
@@ -196,23 +203,36 @@ class Poly:
196
203
  raise NotImplementedError("Cannot invert polynomials without modulus.")
197
204
  return other * self.inv()
198
205
 
199
- def __pow__(self, i: int) -> "Poly":
200
- if not isinstance(i, int):
206
+ def __pow__(self, j: int) -> "Poly":
207
+ if not isinstance(j, int):
201
208
  return NotImplemented
202
209
  zero = 0 * self.coeff[0]
203
210
  one = zero + 1
204
211
  res = self.__class__([one], modulus=self.modulus)
205
- if i < 0:
212
+ if j < 0:
206
213
  if not self.modulus:
207
214
  raise NotImplementedError("Cannot divide polynomials without modulus.")
208
215
  tmp = self.inv()
209
- i *= -1
216
+ j *= -1
210
217
  else:
211
218
  tmp = self
212
- for _ in range(i):
213
- 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
214
226
  return res
215
227
 
228
+ def max(self) -> int:
229
+ "Maximum of the absolute value of all coefficients."
230
+ return max([abs(c) for c in self.coeff])
231
+
232
+ def sum(self) -> int:
233
+ "Sum of the absolute value of all coefficients."
234
+ return sum([abs(c) for c in self.coeff])
235
+
216
236
  def __floordiv__(self, other: "Poly") -> "Poly":
217
237
  return self.divmod(other)[0]
218
238
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.6
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.6"
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