kryptools 1.3.1__tar.gz → 1.3.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-1.3.1 → kryptools-1.3.3}/PKG-INFO +1 -1
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/GF2.py +7 -5
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/Zmod.py +15 -5
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/__init__.py +1 -1
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools.egg-info/PKG-INFO +1 -1
- {kryptools-1.3.1 → kryptools-1.3.3}/pyproject.toml +1 -1
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_GF2.py +25 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_Zmod.py +42 -5
- {kryptools-1.3.1 → kryptools-1.3.3}/LICENSE +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/README.md +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/aes.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/blockcipher.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/code.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/conway_polynomials.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/des.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/dlp.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/dlp_ic.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/dlp_qs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/dlp_rho.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/ec.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_dix.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_ecm.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_fmt.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_pm1.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_qs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/factor_rho.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/intfuncs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/keccak.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/la.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/lat.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/nt.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/poly.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/primes.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools/sha1.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/setup.cfg +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_aes.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_code.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_des.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_dlog.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_ec.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_factor.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_factor_fmt.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_factor_pm1.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_factor_qs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_intfuncs.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_keccak.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_la.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_lat.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_nt.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_poly.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_primes.py +0 -0
- {kryptools-1.3.1 → kryptools-1.3.3}/tests/test_sha1.py +0 -0
|
@@ -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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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^*."
|
|
@@ -98,6 +98,10 @@ class Zmod:
|
|
|
98
98
|
"Return a generator of the group Z_n^*."
|
|
99
99
|
if not self.is_cyclic():
|
|
100
100
|
return None
|
|
101
|
+
if self.n == 1:
|
|
102
|
+
return self(0)
|
|
103
|
+
if self.n == 2:
|
|
104
|
+
return self(1)
|
|
101
105
|
for a in range(2, self.n):
|
|
102
106
|
if gcd(a, self.n) > 1:
|
|
103
107
|
continue
|
|
@@ -109,17 +113,21 @@ class Zmod:
|
|
|
109
113
|
"Return a generator for all generators of the group Z_n^*."
|
|
110
114
|
a = self.generator()
|
|
111
115
|
if a is not None:
|
|
116
|
+
yield a
|
|
112
117
|
self.order()
|
|
113
|
-
for j in range(
|
|
118
|
+
for j in range(2, self.group_order):
|
|
114
119
|
if gcd(j, self.group_order) == 1:
|
|
115
120
|
yield a**j
|
|
116
121
|
|
|
117
122
|
def star(self) -> list:
|
|
118
123
|
"Return a generator for all elements of the group Z_n^*."
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
124
|
+
if self.n == 1:
|
|
125
|
+
yield self(0)
|
|
126
|
+
else:
|
|
127
|
+
yield self(1)
|
|
128
|
+
for a in range(2, self.n):
|
|
129
|
+
if gcd(a, self.n) == 1:
|
|
130
|
+
yield self(a)
|
|
123
131
|
|
|
124
132
|
|
|
125
133
|
class ZmodPoint:
|
|
@@ -221,6 +229,8 @@ class ZmodPoint:
|
|
|
221
229
|
|
|
222
230
|
def order(self) -> int:
|
|
223
231
|
"Compute the order of the point in the group Z_n^*."
|
|
232
|
+
if self.ring.n == 1:
|
|
233
|
+
return 1
|
|
224
234
|
if self.x == 0 or gcd(self.x, self.ring.n) != 1:
|
|
225
235
|
raise ValueError(f"{self.x} and {self.ring.n} are not coprime!")
|
|
226
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.
|
|
8
|
+
__version__ = "1.3.3"
|
|
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
|
|
@@ -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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
from math import gcd
|
|
3
|
-
from kryptools import Zmod, euler_phi
|
|
3
|
+
from kryptools import Zmod, euler_phi, is_prime
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
def test_Zmod_ops():
|
|
@@ -70,9 +70,26 @@ def test_Zmod_methods():
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
def test_Zmod_order():
|
|
73
|
-
for n in range(
|
|
74
|
-
|
|
75
|
-
assert
|
|
73
|
+
for n in range(1, 100):
|
|
74
|
+
o = euler_phi(n)
|
|
75
|
+
assert Zmod(n).order() == o
|
|
76
|
+
assert len(list(Zmod(n).star())) == o
|
|
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
|
+
|
|
90
|
+
def test_Zmod_field():
|
|
91
|
+
for n in range(1, 100):
|
|
92
|
+
assert Zmod(n).is_field() == is_prime(n)
|
|
76
93
|
|
|
77
94
|
|
|
78
95
|
OEIS_A033948 = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 17, 18, 19, 22, 23, 25, 26, 27,
|
|
@@ -80,7 +97,27 @@ OEIS_A033948 = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 13, 14, 17, 18, 19, 22, 23, 25,
|
|
|
80
97
|
79, 81, 82, 83, 86, 89, 94, 97, 98, 101, 103, 106, 107, 109, 113, 118, 121, 122, 125,
|
|
81
98
|
127, 131, 134, 137, 139]
|
|
82
99
|
|
|
83
|
-
|
|
84
100
|
def test_Zmod_cyclic():
|
|
85
101
|
for n in range(2, OEIS_A033948[-1]+1):
|
|
86
102
|
assert Zmod(n).is_cyclic() == (n in OEIS_A033948)
|
|
103
|
+
|
|
104
|
+
OEIS_A046145 = [0, 1, 2, 3, 2, 5, 3, 0, 2, 3, 2, 0, 2, 3, 0, 0, 3, 5, 2, 0, 0, 7, 5, 0, 2, 7, 2, 0, 2, 0, 3, 0, 0, 3, 0,
|
|
105
|
+
0, 2, 3, 0, 0, 6, 0, 3, 0, 0, 5, 5, 0, 3, 3, 0, 0, 2, 5, 0, 0, 0, 3, 2, 0, 2, 3, 0, 0, 0, 0, 2, 0, 0, 0,
|
|
106
|
+
7, 0, 5, 5, 0, 0, 0, 0, 3, 0, 2, 7, 2, 0, 0, 3, 0, 0, 3, 0]
|
|
107
|
+
|
|
108
|
+
def test_Zmod_generator():
|
|
109
|
+
for j, a in enumerate(OEIS_A046145):
|
|
110
|
+
ring = Zmod(j+1)
|
|
111
|
+
aa = ring.generator()
|
|
112
|
+
if aa is None:
|
|
113
|
+
aa = 0
|
|
114
|
+
else:
|
|
115
|
+
assert aa.order() == ring.order()
|
|
116
|
+
assert a == int(aa)
|
|
117
|
+
|
|
118
|
+
def test_Zmod_generators():
|
|
119
|
+
for n in range(1, 100):
|
|
120
|
+
if Zmod(n).is_cyclic():
|
|
121
|
+
assert len(list(Zmod(n).generators())) == euler_phi(euler_phi(n))
|
|
122
|
+
else:
|
|
123
|
+
assert list(Zmod(n).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
|
|
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
|