kryptools 1.3.2__tar.gz → 1.3.4__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 (57) hide show
  1. {kryptools-1.3.2 → kryptools-1.3.4}/PKG-INFO +1 -1
  2. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/GF2.py +7 -5
  3. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/Zmod.py +2 -0
  4. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/__init__.py +1 -1
  5. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/intfuncs.py +10 -11
  6. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools.egg-info/PKG-INFO +1 -1
  7. {kryptools-1.3.2 → kryptools-1.3.4}/pyproject.toml +1 -1
  8. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_GF2.py +25 -0
  9. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_Zmod.py +16 -1
  10. {kryptools-1.3.2 → kryptools-1.3.4}/LICENSE +0 -0
  11. {kryptools-1.3.2 → kryptools-1.3.4}/README.md +0 -0
  12. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/aes.py +0 -0
  13. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/blockcipher.py +0 -0
  14. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/code.py +0 -0
  15. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/conway_polynomials.py +0 -0
  16. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/des.py +0 -0
  17. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/dlp.py +0 -0
  18. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/dlp_bsgs.py +0 -0
  19. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/dlp_ic.py +0 -0
  20. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/dlp_qs.py +0 -0
  21. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/dlp_rho.py +0 -0
  22. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/ec.py +0 -0
  23. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor.py +0 -0
  24. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_dix.py +0 -0
  25. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_ecm.py +0 -0
  26. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_fmt.py +0 -0
  27. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_pm1.py +0 -0
  28. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_qs.py +0 -0
  29. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/factor_rho.py +0 -0
  30. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/keccak.py +0 -0
  31. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/la.py +0 -0
  32. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/lat.py +0 -0
  33. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/nt.py +0 -0
  34. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/poly.py +0 -0
  35. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/primes.py +0 -0
  36. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools/sha1.py +0 -0
  37. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools.egg-info/SOURCES.txt +0 -0
  38. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools.egg-info/dependency_links.txt +0 -0
  39. {kryptools-1.3.2 → kryptools-1.3.4}/kryptools.egg-info/top_level.txt +0 -0
  40. {kryptools-1.3.2 → kryptools-1.3.4}/setup.cfg +0 -0
  41. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_aes.py +0 -0
  42. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_code.py +0 -0
  43. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_des.py +0 -0
  44. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_dlog.py +0 -0
  45. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_ec.py +0 -0
  46. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_factor.py +0 -0
  47. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_factor_fmt.py +0 -0
  48. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_factor_pm1.py +0 -0
  49. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_factor_qs.py +0 -0
  50. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_intfuncs.py +0 -0
  51. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_keccak.py +0 -0
  52. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_la.py +0 -0
  53. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_lat.py +0 -0
  54. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_nt.py +0 -0
  55. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_poly.py +0 -0
  56. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_primes.py +0 -0
  57. {kryptools-1.3.2 → kryptools-1.3.4}/tests/test_sha1.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  License: MIT
@@ -51,7 +51,7 @@ class GF2:
51
51
  self.order = 2**n # 2**n
52
52
  self.print_hex: bool = True
53
53
  self.byteorder: str = "big" # big|little
54
- self.mult_order = self.order -1
54
+ self.mult_order = self.order - 1
55
55
  self.factors = {} # factoring of the group order
56
56
 
57
57
  def __repr__(self):
@@ -99,6 +99,8 @@ class GF2:
99
99
 
100
100
  def generator(self) -> int | None:
101
101
  "Return a generator of the group GF(2^n)^*."
102
+ if self.power == 1:
103
+ return self(1)
102
104
  for a in range(2, self.order):
103
105
  a = self(a)
104
106
  if a.is_generator():
@@ -107,10 +109,10 @@ class GF2:
107
109
  def generators(self) -> list | None:
108
110
  "Return a generator for all generators of the group GF(2^n)^*."
109
111
  a = self.generator()
110
- if a is not None:
111
- for j in range(1, self.mult_order):
112
- if gcd(j, self.mult_order) == 1:
113
- yield a**j
112
+ yield a
113
+ for j in range(2, self.mult_order):
114
+ if gcd(j, self.mult_order) == 1:
115
+ yield a**j
114
116
 
115
117
  def star(self) -> list:
116
118
  "Return a generator for all elements of the group GF(2^n)n^*."
@@ -229,6 +229,8 @@ class ZmodPoint:
229
229
 
230
230
  def order(self) -> int:
231
231
  "Compute the order of the point in the group Z_n^*."
232
+ if self.ring.n == 1:
233
+ return 1
232
234
  if self.x == 0 or gcd(self.x, self.ring.n) != 1:
233
235
  raise ValueError(f"{self.x} and {self.ring.n} are not coprime!")
234
236
  order = self.ring.order() # use euler_phi(n) as our current guess
@@ -5,7 +5,7 @@ Implemenation of same basic algorithms used in cryptography.
5
5
  __author__ = "Gerald Teschl"
6
6
  __copyright__ = "Copyright 2024-2025, Gerald Teschl"
7
7
  __license__ = "MIT License"
8
- __version__ = "1.3.2"
8
+ __version__ = "1.3.4"
9
9
  __email__ = "Gerald.Teschl@univie.ac.at"
10
10
 
11
11
  from .nt import egcd, cf, convergents, legendre_symbol, jacobi_symbol, sqrt_mod, euler_phi, carmichael_lambda, moebius_mu, is_carmichael_number, order, crt
@@ -18,19 +18,18 @@ def iroot(k: int, n: int) -> int:
18
18
  raise ValueError(f"n={n} must be a nonegative integer.")
19
19
  if n <= 1 or k == 1:
20
20
  return n
21
- if k == 2:
21
+ if k == 2: # use the faster internal function
22
22
  return isqrt(n)
23
- rr = n
24
- kk = k
25
- while kk > 1:
26
- kk //= 2
27
- rr = isqrt(rr)
28
- r = rr + 1
29
- k1 = k-1
30
- while rr < r:
23
+ l = n.bit_length()
24
+ if k >= l:
25
+ return 1
26
+ r = 1 << ((l-1)//k + 1) # use 2^ceil(l/k) as starting value
27
+ k1 = k - 1
28
+ while True:
29
+ rr = (k1 * r + n // r ** k1) // k # Newton iteration
30
+ if rr >= r:
31
+ return r
31
32
  r = rr
32
- rr = (k1 * rr + n // rr ** k1) // k # Newton iteration
33
- return r
34
33
 
35
34
 
36
35
  def ilog(b: int, n: int) -> int:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kryptools
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: Implemenation of same basic algorithms used in cryptography.
5
5
  Author-email: Gerald Teschl <gerald.teschl@univie.ac.at>
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kryptools"
3
- version = "1.3.2"
3
+ version = "1.3.4"
4
4
  authors = [
5
5
  { name="Gerald Teschl", email="gerald.teschl@univie.ac.at" },
6
6
  ]
@@ -33,3 +33,28 @@ def test_GF2_ops():
33
33
  for _ in range(num_tests):
34
34
  a = randint(1, gf.order-1)
35
35
  assert (gf(a)**-1).poly() == gf(a).poly().inv()
36
+
37
+ def test_GF2_order():
38
+ for n in range(1, 8):
39
+ gf = GF2(n)
40
+ assert len(list(gf)) == gf.order
41
+ assert len(list(gf.star())) == gf.order - 1
42
+ assert len(list(gf.generators())) == euler_phi(gf.order - 1)
43
+
44
+ def test_GF2P_order():
45
+ for n in range(1, 9):
46
+ gf = GF2(n)
47
+ one = gf(1)
48
+ for x in gf.star():
49
+ o = 1
50
+ xx = x
51
+ while xx != one:
52
+ o += 1
53
+ xx *=x
54
+ assert o == x.order()
55
+
56
+ def test_Zmod_generator():
57
+ for n in range(1, 9):
58
+ gf = GF2(n)
59
+ a = gf.generator()
60
+ assert a.order() == gf.mult_order
@@ -75,6 +75,18 @@ def test_Zmod_order():
75
75
  assert Zmod(n).order() == o
76
76
  assert len(list(Zmod(n).star())) == o
77
77
 
78
+ def test_ZmodP_order():
79
+ for n in range(1,100):
80
+ ring = Zmod(n)
81
+ one = ring(1)
82
+ for x in ring.star():
83
+ o = 1
84
+ xx = x
85
+ while xx != one:
86
+ o += 1
87
+ xx *=x
88
+ assert o == x.order()
89
+
78
90
  def test_Zmod_field():
79
91
  for n in range(1, 100):
80
92
  assert Zmod(n).is_field() == is_prime(n)
@@ -95,9 +107,12 @@ OEIS_A046145 = [0, 1, 2, 3, 2, 5, 3, 0, 2, 3, 2, 0, 2, 3, 0, 0, 3, 5, 2, 0, 0, 7
95
107
 
96
108
  def test_Zmod_generator():
97
109
  for j, a in enumerate(OEIS_A046145):
98
- aa = Zmod(j+1).generator()
110
+ ring = Zmod(j+1)
111
+ aa = ring.generator()
99
112
  if aa is None:
100
113
  aa = 0
114
+ else:
115
+ assert aa.order() == ring.order()
101
116
  assert a == int(aa)
102
117
 
103
118
  def test_Zmod_generators():
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
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes