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.
Files changed (28) hide show
  1. {kryptools-0.9.2 → kryptools-0.9.3}/PKG-INFO +1 -1
  2. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/Zmod.py +20 -0
  3. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/__init__.py +1 -1
  4. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/primes.py +27 -2
  5. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/PKG-INFO +1 -1
  6. {kryptools-0.9.2 → kryptools-0.9.3}/pyproject.toml +1 -1
  7. {kryptools-0.9.2 → kryptools-0.9.3}/LICENSE +0 -0
  8. {kryptools-0.9.2 → kryptools-0.9.3}/README.md +0 -0
  9. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp.py +0 -0
  10. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_bsgs.py +0 -0
  11. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_ic.py +0 -0
  12. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_qs.py +0 -0
  13. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/dlp_rho.py +0 -0
  14. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/ec.py +0 -0
  15. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor.py +0 -0
  16. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_dix.py +0 -0
  17. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_ecm.py +0 -0
  18. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_fmt.py +0 -0
  19. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_pm1.py +0 -0
  20. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/factor_qs.py +0 -0
  21. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/la.py +0 -0
  22. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/lat.py +0 -0
  23. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/nt.py +0 -0
  24. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools/poly.py +0 -0
  25. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/SOURCES.txt +0 -0
  26. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/dependency_links.txt +0 -0
  27. {kryptools-0.9.2 → kryptools-0.9.3}/kryptools.egg-info/top_level.txt +0 -0
  28. {kryptools-0.9.2 → kryptools-0.9.3}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.9.2
3
+ Version: 0.9.3
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
@@ -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(n) find a pseudorandom safe prime with bit length at least l and ord(2)=(p-1)/2
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kryptools
3
- Version: 0.9.2
3
+ Version: 0.9.3
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.2"
3
+ version = "0.9.3"
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