kryptools 1.5.2__tar.gz → 1.5.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.5.2 → kryptools-1.5.3}/PKG-INFO +1 -1
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/GF2.py +2 -8
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/__init__.py +1 -1
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/code.py +9 -9
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/poly.py +4 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools.egg-info/PKG-INFO +1 -1
- {kryptools-1.5.2 → kryptools-1.5.3}/pyproject.toml +1 -1
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_poly.py +7 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/LICENSE +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/README.md +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/Zmod.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/aes.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/blockcipher.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/conway_polynomials.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/des.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/dlp.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/dlp_ic.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/dlp_qs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/dlp_rho.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/ec.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_dix.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_ecm.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_fmt.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_pm1.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_qs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/factor_rho.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/intfuncs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/keccak.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/la.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/lat.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/nt.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/primes.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools/sha1.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/setup.cfg +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_GF2.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_Zmod.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_aes.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_code.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_des.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_dlog.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_ec.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_factor.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_factor_fmt.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_factor_pm1.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_factor_qs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_intfuncs.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_keccak.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_la.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_lat.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_nt.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_primes.py +0 -0
- {kryptools-1.5.2 → kryptools-1.5.3}/tests/test_sha1.py +0 -0
|
@@ -195,18 +195,12 @@ class GF2nPoint:
|
|
|
195
195
|
raise NotImplementedError("Cannot add elements from different fields.")
|
|
196
196
|
return self.field(self.x ^ other.x)
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
return self
|
|
198
|
+
__sub__ = __add__
|
|
200
199
|
|
|
201
200
|
def __pos__(self) -> "GF2nPoint":
|
|
202
201
|
return self
|
|
203
202
|
|
|
204
|
-
|
|
205
|
-
if not isinstance(other, self.__class__):
|
|
206
|
-
return NotImplemented
|
|
207
|
-
if self.field != other.field:
|
|
208
|
-
raise NotImplementedError("Cannot add elements from different fields.")
|
|
209
|
-
return self.field(self.x ^ other.x)
|
|
203
|
+
__neg__ = __pos__
|
|
210
204
|
|
|
211
205
|
def __mul__(self, other: "GF2nPoint") -> "GF2nPoint":
|
|
212
206
|
if isinstance(other, int):
|
|
@@ -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.5.
|
|
8
|
+
__version__ = "1.5.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
|
|
@@ -102,7 +102,7 @@ class Goppa():
|
|
|
102
102
|
self.G = gen2pchk(self.H)
|
|
103
103
|
|
|
104
104
|
def __repr__(self):
|
|
105
|
-
return f"Binary irreducible Goppa code over GF(2^{self.gf.
|
|
105
|
+
return f"Binary irreducible Goppa [{self.G.cols}, {self.G.rows}] code over GF(2^{self.gf.degree}) with polynomial g(x) = {self.g}."
|
|
106
106
|
|
|
107
107
|
def encode(self, x: list[int]):
|
|
108
108
|
"Encode a given list of bits."
|
|
@@ -246,12 +246,12 @@ class ReedSolomonCode(CyclicCode):
|
|
|
246
246
|
>>> rsc = ReedSolomonCode(k, gf)
|
|
247
247
|
|
|
248
248
|
To encode a list of letters (the length must be equal to the dimension k of the code; conversion to the Galois field is done automatically):
|
|
249
|
-
>>>
|
|
250
|
-
[
|
|
249
|
+
>>> rsc.encode([1, 2, 3])
|
|
250
|
+
[6, 4, 5, 1, 8, 4, 2, 9, 2, 8, 9, 6]
|
|
251
251
|
|
|
252
|
-
|
|
253
|
-
>>>
|
|
254
|
-
[
|
|
252
|
+
To decoding use:
|
|
253
|
+
>>> rsc.decode([1, 4, 4, 0, 8, 4, 2, 9, 2, 0, 9, 6])
|
|
254
|
+
[1, 2, 3]
|
|
255
255
|
|
|
256
256
|
"""
|
|
257
257
|
def __init__(self, k:int, gf, alpha = None): # pylint: disable=W0231
|
|
@@ -279,9 +279,9 @@ class ReedSolomonCode(CyclicCode):
|
|
|
279
279
|
assert self.g * self.h == self.modulus
|
|
280
280
|
|
|
281
281
|
def __repr__(self):
|
|
282
|
-
return f"Reed-Solomon
|
|
282
|
+
return f"Reed-Solomon [{self.n}, {self.k}, {self.d}] code over GF({self.n+1})."
|
|
283
283
|
|
|
284
|
-
def encode(self, x: list|Poly): # pylint: disable=W0221
|
|
284
|
+
def encode(self, x: list|Poly) -> list|Poly: # pylint: disable=W0221
|
|
285
285
|
"Encode a given list or polynomial."
|
|
286
286
|
as_list = False
|
|
287
287
|
zero = 0 * self.g[0]
|
|
@@ -295,7 +295,7 @@ class ReedSolomonCode(CyclicCode):
|
|
|
295
295
|
return y + [zero] * (self.n - len(y))
|
|
296
296
|
return Poly(y)
|
|
297
297
|
|
|
298
|
-
def decode(self, y: list|Poly): # pylint: disable=W0221
|
|
298
|
+
def decode(self, y: list|Poly) -> list|Poly: # pylint: disable=W0221
|
|
299
299
|
"Decode a given list or polynomial."
|
|
300
300
|
as_list = False
|
|
301
301
|
zero = 0 * self.g[0]
|
|
@@ -130,6 +130,10 @@ class Poly:
|
|
|
130
130
|
"Return the degree."
|
|
131
131
|
return len(self.coeff) - 1
|
|
132
132
|
|
|
133
|
+
def weight(self) -> int:
|
|
134
|
+
"Return the number of nonzero coefficients."
|
|
135
|
+
return sum(map(bool,self.coeff))
|
|
136
|
+
|
|
133
137
|
def map(self, func):
|
|
134
138
|
"Apply a given function to all coefficients in place."
|
|
135
139
|
self.coeff = list(map(func, self.coeff))
|
|
@@ -8,8 +8,15 @@ seed(0)
|
|
|
8
8
|
num_tests = 10
|
|
9
9
|
|
|
10
10
|
def test_Poly():
|
|
11
|
+
assert Poly([0]).weight() == 0
|
|
12
|
+
assert Poly([1]).weight() == 1
|
|
13
|
+
assert Poly([1]).degree() == 0
|
|
11
14
|
p = Poly([2, 0, 2])
|
|
12
15
|
q = Poly([1, 2, 3, 4])
|
|
16
|
+
assert p.degree() == 2
|
|
17
|
+
assert p.weight() == 2
|
|
18
|
+
assert q.degree() == 3
|
|
19
|
+
assert q.weight() == 4
|
|
13
20
|
d, m = q.divmod(p)
|
|
14
21
|
assert d * p + m == q
|
|
15
22
|
for _ in range(num_tests):
|
|
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
|