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.
- {kryptools-0.9 → kryptools-0.9.1}/PKG-INFO +1 -1
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/__init__.py +1 -1
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/la.py +7 -7
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/lat.py +2 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/primes.py +18 -6
- {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/PKG-INFO +1 -1
- {kryptools-0.9 → kryptools-0.9.1}/pyproject.toml +1 -1
- {kryptools-0.9 → kryptools-0.9.1}/LICENSE +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/README.md +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/Zmod.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_ic.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_qs.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/dlp_rho.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/ec.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_dix.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_ecm.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_fmt.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_pm1.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/factor_qs.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/nt.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools/poly.py +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-0.9 → kryptools-0.9.1}/setup.cfg +0 -0
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
|
@@ -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
|
|
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*
|
|
26
|
-
qq =
|
|
27
|
-
p =
|
|
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))
|
|
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
|