kryptools 0.9.2__tar.gz → 0.9.3__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.2 → kryptools-0.9.3}/PKG-INFO +1 -1
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/Zmod.py +20 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/__init__.py +1 -1
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/primes.py +27 -2
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/PKG-INFO +1 -1
- {kryptools-0.9.2 → kryptools-0.9.3}/pyproject.toml +1 -1
- {kryptools-0.9.2 → kryptools-0.9.3}/LICENSE +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/README.md +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_ic.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_qs.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_rho.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/ec.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_dix.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_ecm.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_fmt.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_pm1.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_qs.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/la.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/lat.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/nt.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/poly.py +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-0.9.2 → kryptools-0.9.3}/setup.cfg +0 -0
|
@@ -62,6 +62,26 @@ class Zmod:
|
|
|
62
62
|
self.group_order *= p**k
|
|
63
63
|
return self.group_order
|
|
64
64
|
|
|
65
|
+
def generator(self, all = False) -> int:
|
|
66
|
+
"""Return a generator of the group Z_n^*."""
|
|
67
|
+
for a in range(2, self.n):
|
|
68
|
+
if gcd(a, self.n) > 1:
|
|
69
|
+
continue
|
|
70
|
+
a = self(a)
|
|
71
|
+
if a.is_generator():
|
|
72
|
+
if all:
|
|
73
|
+
self.order()
|
|
74
|
+
return list( a**j for j in range(1, self.group_order) if gcd(j,self.group_order) == 1 )
|
|
75
|
+
return a
|
|
76
|
+
|
|
77
|
+
def star(self) -> int:
|
|
78
|
+
"""Return a list of all elements of the group Z_n^*."""
|
|
79
|
+
elements = [ 1 ]
|
|
80
|
+
for a in range(2, self.n):
|
|
81
|
+
if gcd(a, self.n) > 1:
|
|
82
|
+
continue
|
|
83
|
+
elements.append(self(a))
|
|
84
|
+
return elements
|
|
65
85
|
|
|
66
86
|
class ZmodPoint:
|
|
67
87
|
"Represents a point in the ring Zmod."
|
|
@@ -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, moebius_mu, order, crt
|
|
6
|
-
from .primes import sieve_eratosthenes, is_prime, next_prime, previous_prime, random_prime, random_strongprime, is_safeprime, random_safeprime
|
|
6
|
+
from .primes import sieve_eratosthenes, prime_pi, is_prime, next_prime, previous_prime, random_prime, random_strongprime, is_safeprime, random_safeprime
|
|
7
7
|
from .factor import factorint, divisors
|
|
8
8
|
from .dlp import dlog
|
|
9
9
|
from .ec import EC_Weierstrass
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Tools for prime numbers:
|
|
3
3
|
sieve_eratosthenes(B) a tuple of all primes up to including B
|
|
4
|
+
prime_pi(n) number of primes below or equal n
|
|
4
5
|
is_prime(n) test if n is probably prime
|
|
5
6
|
next_prime(n) find the next prime larger or equal n
|
|
6
7
|
previous_prime(n) find the previous prime smaller or equal n
|
|
7
8
|
random_prime(l) find a pseudorandom prime with bit length at least l
|
|
8
9
|
random_strongprime(l) find a pseudorandom strong prime with bit length at least l
|
|
9
10
|
is_safeprime(n) test if n is a safe prime
|
|
10
|
-
random_safeprime(
|
|
11
|
+
random_safeprime(l) find a pseudorandom safe prime with bit length at least l and ord(2)=(p-1)/2
|
|
12
|
+
is_blumprime(n) test if n is a Blum prime
|
|
13
|
+
random_blumprime(l) find a pseudorandom Blum prime with bit length at least l
|
|
11
14
|
miller_rabin_test(n, b) Miller-Rabin primality test with base b
|
|
12
15
|
"""
|
|
13
|
-
from math import isqrt, gcd
|
|
16
|
+
from math import isqrt, gcd, floor
|
|
14
17
|
from random import randint
|
|
15
18
|
from .nt import jacobi_symbol
|
|
16
19
|
|
|
@@ -18,6 +21,11 @@ from .nt import jacobi_symbol
|
|
|
18
21
|
|
|
19
22
|
def sieve_eratosthenes(B: int) -> tuple:
|
|
20
23
|
"""Returns a tuple of all primes up to (including) `B`."""
|
|
24
|
+
if B < 2:
|
|
25
|
+
return ()
|
|
26
|
+
if B < 3:
|
|
27
|
+
return [2]
|
|
28
|
+
B= floor(B)
|
|
21
29
|
B1 = (isqrt(B) - 1)//2
|
|
22
30
|
B = (B - 1)//2
|
|
23
31
|
isprime = [True] * (B + 1) # to begin with, all odd numbers are potentially prime
|
|
@@ -30,6 +38,11 @@ def sieve_eratosthenes(B: int) -> tuple:
|
|
|
30
38
|
|
|
31
39
|
return tuple([2] + [2 * q + 1 for q in range(1, B + 1) if isprime[q]])
|
|
32
40
|
|
|
41
|
+
def prime_pi(x: float) -> int:
|
|
42
|
+
"""Prime-counting function pi(x). Returns the number of primes below or equal `x`."""
|
|
43
|
+
return len(sieve_eratosthenes(x))
|
|
44
|
+
|
|
45
|
+
|
|
33
46
|
# Primality testing
|
|
34
47
|
|
|
35
48
|
|
|
@@ -115,6 +128,18 @@ def random_safeprime(l: int) -> int:
|
|
|
115
128
|
p += 24
|
|
116
129
|
return p
|
|
117
130
|
|
|
131
|
+
def is_blumprime(p: int) -> bool:
|
|
132
|
+
"""Tests if a number is a Blum prime."""
|
|
133
|
+
return p % 4 == 3 and is_prime(p)
|
|
134
|
+
|
|
135
|
+
def random_blumprime(l: int) -> int:
|
|
136
|
+
"""Find a pseudorandom Blum prime with bit length at least `l`."""
|
|
137
|
+
p = randint(2 ** (l - 1), 2**l - 1)
|
|
138
|
+
p = p - (p % 4) + 3
|
|
139
|
+
while not is_prime(p):
|
|
140
|
+
p += 4
|
|
141
|
+
return p
|
|
142
|
+
|
|
118
143
|
def _lucas_sequence(n, D, k):
|
|
119
144
|
"""Evaluate a Lucas sequence."""
|
|
120
145
|
# P = 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
|
|
File without changes
|