kryptools 0.9__tar.gz → 0.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 (28) hide show
  1. {kryptools-0.9 → kryptools-0.9.1}/PKG-INFO +1 -1
  2. {kryptools-0.9 → kryptools-0.9.1}/kryptools/__init__.py +1 -1
  3. {kryptools-0.9 → kryptools-0.9.1}/kryptools/la.py +7 -7
  4. {kryptools-0.9 → kryptools-0.9.1}/kryptools/lat.py +2 -0
  5. {kryptools-0.9 → kryptools-0.9.1}/kryptools/primes.py +18 -6
  6. {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/PKG-INFO +1 -1
  7. {kryptools-0.9 → kryptools-0.9.1}/pyproject.toml +1 -1
  8. {kryptools-0.9 → kryptools-0.9.1}/LICENSE +0 -0
  9. {kryptools-0.9 → kryptools-0.9.1}/README.md +0 -0
  10. {kryptools-0.9 → kryptools-0.9.1}/kryptools/Zmod.py +0 -0
  11. {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp.py +0 -0
  12. {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_bsgs.py +0 -0
  13. {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_ic.py +0 -0
  14. {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_qs.py +0 -0
  15. {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_rho.py +0 -0
  16. {kryptools-0.9 → kryptools-0.9.1}/kryptools/ec.py +0 -0
  17. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor.py +0 -0
  18. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_dix.py +0 -0
  19. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_ecm.py +0 -0
  20. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_fmt.py +0 -0
  21. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_pm1.py +0 -0
  22. {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_qs.py +0 -0
  23. {kryptools-0.9 → kryptools-0.9.1}/kryptools/nt.py +0 -0
  24. {kryptools-0.9 → kryptools-0.9.1}/kryptools/poly.py +0 -0
  25. {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/SOURCES.txt +0 -0
  26. {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/dependency_links.txt +0 -0
  27. {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/top_level.txt +0 -0
  28. {kryptools-0.9 → kryptools-0.9.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.9
3
+ Version: 0.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
  Project-URL: Homepage, https://github.com/teschlg/kryptools
@@ -3,7 +3,7 @@ Implemenation of same basic algorithms used in cryptography.
3
3
  """
4
4
 
5
5
  from .nt import egcd, cf, convergents, legendre_symbol, jacobi_symbol, sqrt_mod, euler_phi, carmichael_lambda, order, crt
6
- from .primes import sieve_eratosthenes, is_prime, next_prime, random_prime, random_strongprime, is_safeprime, random_safeprime
6
+ from .primes import sieve_eratosthenes, is_prime, next_prime, previous_prime, random_prime, random_strongprime, is_safeprime, random_safeprime
7
7
  from .factor import factorint
8
8
  from .dlp import dlog
9
9
  from .ec import EC_Weierstrass
@@ -211,7 +211,7 @@ class Matrix:
211
211
 
212
212
  def det(self) -> int:
213
213
  "Compute the determinant of a matrix M."
214
- if self.rows != self.rows:
214
+ if self.rows != self.cols:
215
215
  raise ValueError("Matrix must be square!")
216
216
  n, m = self.cols, self.rows
217
217
  R = self[:, :]
@@ -239,7 +239,7 @@ class Matrix:
239
239
 
240
240
  def inv(self) -> "Matrix":
241
241
  "Compute the inverse of a square matrix M."
242
- if self.rows != self.rows:
242
+ if self.rows != self.cols:
243
243
  raise ValueError("Matrix must be square!")
244
244
  n = self.cols
245
245
  MM = Matrix([[0 for _ in range(2*n)] for _ in range(n)])
@@ -253,7 +253,7 @@ class Matrix:
253
253
 
254
254
  def is_unimodular(self) -> bool:
255
255
  "Test if the matrix is unimodular."
256
- if self.rows != self.rows:
256
+ if self.rows != self.cols:
257
257
  return False
258
258
  def is_integer(i):
259
259
  if isinstance(i, int) or (isinstance(i, Fraction) and i.denominator == 1):
@@ -262,7 +262,7 @@ class Matrix:
262
262
  return all([is_integer(i) for i in self]) and self.det()**2 == 1
263
263
 
264
264
  def zeros(self, m: int = None, n: int = None):
265
- "Returns a zero matrix of the same dimension"
265
+ "Returns a zero matrix of the same dimension."
266
266
  if not m and not n:
267
267
  n, m = self.cols, self.rows
268
268
  elif not n:
@@ -274,7 +274,7 @@ class Matrix:
274
274
  return Matrix([[ zero for j in range(n) ] for i in range(m) ])
275
275
 
276
276
  def eye(self, m: int = None, n: int = None):
277
- "Returns an identity matrix of the same dimension"
277
+ "Returns an identity matrix of the same dimension."
278
278
  def delta(i, j):
279
279
  if i == j:
280
280
  return one
@@ -292,13 +292,13 @@ class Matrix:
292
292
 
293
293
 
294
294
  def zeros(m: int, n: int = None, zero = 0) -> "Matrix":
295
- "Returns a zero matrix of the given dimension"
295
+ "Returns a zero matrix of the given dimension."
296
296
  if not n:
297
297
  n = m
298
298
  return Matrix([[ zero for j in range(n) ] for i in range(m) ])
299
299
 
300
300
  def eye(m:int, n: int = None) -> "Matrix":
301
- "Returns an identity matrix of the given dimension"
301
+ "Returns an identity matrix of the given dimension."
302
302
  def delta(i, j):
303
303
  if i == j:
304
304
  return 1
@@ -42,6 +42,8 @@ def hermite_nf(M: Matrix) -> Matrix:
42
42
  H[:, jj] -= tmp * H[:, j]
43
43
  #print(H)
44
44
  j -= 1
45
+ if j < 0:
46
+ break
45
47
  while H.cols> 1 and all(not H[i, 0] for i in range(m)): # remove zero columns
46
48
  H = H[:,1:]
47
49
  return H
@@ -3,6 +3,7 @@ Tools for prime numbers:
3
3
  sieve_eratosthenes(B) a tuple of all primes up to including B
4
4
  is_prime(n) test if n is probably prime
5
5
  next_prime(n) find the next prime larger or equal n
6
+ previous_prime(n) find the previous prime smaller or equal n
6
7
  random_prime(l) find a pseudorandom prime with bit length at least l
7
8
  random_strongprime(l) find a pseudorandom strong prime with bit length at least l
8
9
  is_safeprime(n) test if n is a safe prime
@@ -17,14 +18,14 @@ from .nt import jacobi_symbol
17
18
 
18
19
  def sieve_eratosthenes(B: int) -> tuple:
19
20
  """Returns a tuple of all primes up to (including) `B`."""
20
- B1 = (isqrt(B) -1)//2
21
+ B1 = (isqrt(B) - 1)//2
21
22
  B = (B - 1)//2
22
- isprime = [True] * (B + 1) # to begin with, all numbers are potentially prime
23
- # sieve out the primes p=2*q+1 starting at 3 in steps of 2 (ignoring even numbers)
23
+ isprime = [True] * (B + 1) # to begin with, all odd numbers are potentially prime
24
+ # sieve out the primes p=2*q+1 starting at q = 1
24
25
  for q in range(1, B1 + 1):
25
- if isprime[q]: # sieve out all multiples; numbers p*q with q<p were already sieved out previously
26
- qq = (q << 1) * (q + 1)
27
- p = (q << 1) | 1
26
+ if isprime[q]: # sieve out all multiples; numbers p*r with r<p were already sieved out previously
27
+ qq = 2 * q * (q + 1)
28
+ p = 2 * q + 1
28
29
  isprime[qq :: p] = [False] * ((B - qq) // p + 1)
29
30
 
30
31
  return tuple([2] + [2 * q + 1 for q in range(1, B + 1) if isprime[q]])
@@ -67,11 +68,22 @@ def is_prime(n: int) -> bool:
67
68
 
68
69
  def next_prime(n: int) -> int:
69
70
  """Find the next prime larger or equal `n`."""
71
+ if n < 3:
72
+ return 2
70
73
  n |= 1 # make sure n is odd
71
74
  while not is_prime(n):
72
75
  n += 2
73
76
  return n
74
77
 
78
+ def previous_prime(n: int) -> int:
79
+ """Find the previous prime smaller or equal `n`."""
80
+ if n < 3:
81
+ return 2
82
+ n += (n & 1) - 1 # make sure n is odd
83
+ while not is_prime(n):
84
+ n -= 2
85
+ return n
86
+
75
87
  def random_prime(l: int) -> int:
76
88
  """Find a pseudorandom prime with bit length at least `l`."""
77
89
  return next_prime(randint(2 ** (l - 1), 2**l - 1))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.9
3
+ Version: 0.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
  Project-URL: Homepage, https://github.com/teschlg/kryptools
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kryptools"
3
- version = "0.9"
3
+ version = "0.9.1"
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