kryptools 1.6__tar.gz → 1.7__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.6 → kryptools-1.7}/PKG-INFO +4 -2
- {kryptools-1.6 → kryptools-1.7}/README.md +3 -1
- {kryptools-1.6 → kryptools-1.7}/kryptools/GF2.py +39 -10
- {kryptools-1.6 → kryptools-1.7}/kryptools/__init__.py +4 -4
- kryptools-1.7/kryptools/code.py +664 -0
- kryptools-1.7/kryptools/la.py +952 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/poly.py +197 -2
- {kryptools-1.6 → kryptools-1.7}/kryptools/primes.py +1 -1
- {kryptools-1.6 → kryptools-1.7}/kryptools.egg-info/PKG-INFO +4 -2
- {kryptools-1.6 → kryptools-1.7}/pyproject.toml +1 -1
- {kryptools-1.6 → kryptools-1.7}/tests/test_GF2.py +14 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_code.py +2 -2
- kryptools-1.7/tests/test_la.py +92 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_poly.py +23 -3
- kryptools-1.6/kryptools/code.py +0 -359
- kryptools-1.6/kryptools/la.py +0 -498
- kryptools-1.6/tests/test_la.py +0 -41
- {kryptools-1.6 → kryptools-1.7}/LICENSE +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/Zmod.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/aes.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/blockcipher.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/conway_polynomials.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/des.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/dlp.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/dlp_ic.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/dlp_qs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/dlp_rho.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/ec.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_dix.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_ecm.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_fmt.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_pm1.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_qs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/factor_rho.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/intfuncs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/keccak.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/lat.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/nt.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools/sha1.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-1.6 → kryptools-1.7}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-1.6 → kryptools-1.7}/setup.cfg +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_Zmod.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_aes.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_des.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_dlog.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_ec.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_factor.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_factor_fmt.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_factor_pm1.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_factor_qs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_intfuncs.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_keccak.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_lat.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_nt.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_primes.py +0 -0
- {kryptools-1.6 → kryptools-1.7}/tests/test_sha1.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kryptools
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.7
|
|
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
|
|
@@ -48,10 +48,12 @@ The tools contained are:
|
|
|
48
48
|
* linear codes: Hamming distance, left standard form, parity check matrix
|
|
49
49
|
|
|
50
50
|
* Matrix: a class for Matrices (inverse, det, reduced echelon form, kernel, etc.)
|
|
51
|
+
* BinaryMatrix: a class for Matrices with binary entries (for much faster row operations)
|
|
51
52
|
* Poly: a class for polynomials (division, modulo, factoring and irreducibility test over finite fields, Lagrange interpolation)
|
|
52
53
|
* Zmod: a class for the ring of integers modulo an integer
|
|
53
54
|
* GF2: a class for Galois fields GF(2^n)
|
|
54
|
-
*
|
|
55
|
+
* BinaryCode: a class for encoding and decoding binary linear codes
|
|
56
|
+
* GoppaCode: a class for encoding and decoding binary Goppa codes
|
|
55
57
|
* CyclicCode: a class for encoding and decoding cyclic codes
|
|
56
58
|
* ReedSolomonCode: a class for encoding and decoding Reed-Solomon codes
|
|
57
59
|
* BCHCode: a class for encoding and decoding primitive narrow sense BCH codes
|
|
@@ -30,10 +30,12 @@ The tools contained are:
|
|
|
30
30
|
* linear codes: Hamming distance, left standard form, parity check matrix
|
|
31
31
|
|
|
32
32
|
* Matrix: a class for Matrices (inverse, det, reduced echelon form, kernel, etc.)
|
|
33
|
+
* BinaryMatrix: a class for Matrices with binary entries (for much faster row operations)
|
|
33
34
|
* Poly: a class for polynomials (division, modulo, factoring and irreducibility test over finite fields, Lagrange interpolation)
|
|
34
35
|
* Zmod: a class for the ring of integers modulo an integer
|
|
35
36
|
* GF2: a class for Galois fields GF(2^n)
|
|
36
|
-
*
|
|
37
|
+
* BinaryCode: a class for encoding and decoding binary linear codes
|
|
38
|
+
* GoppaCode: a class for encoding and decoding binary Goppa codes
|
|
37
39
|
* CyclicCode: a class for encoding and decoding cyclic codes
|
|
38
40
|
* ReedSolomonCode: a class for encoding and decoding Reed-Solomon codes
|
|
39
41
|
* BCHCode: a class for encoding and decoding primitive narrow sense BCH codes
|
|
@@ -35,7 +35,7 @@ class GF2:
|
|
|
35
35
|
f6
|
|
36
36
|
|
|
37
37
|
"""
|
|
38
|
-
def __init__(self, n: int, modulus: int | None = None):
|
|
38
|
+
def __init__(self, n: int, modulus: int | None = None, cached = False):
|
|
39
39
|
if not isinstance(n, int) or n < 1:
|
|
40
40
|
raise ValueError(f"{n} is not a positive integer.")
|
|
41
41
|
if not modulus:
|
|
@@ -55,6 +55,11 @@ class GF2:
|
|
|
55
55
|
self.byteorder: str = "big" # big|little
|
|
56
56
|
self.mult_order = self.order - 1
|
|
57
57
|
self.factors = {} # factoring of the group order
|
|
58
|
+
self.cached = False # use precomputed log/exp tables to speed up multiplication
|
|
59
|
+
self.log = None # precomputed log table
|
|
60
|
+
self.exp = None # precomputed exp table
|
|
61
|
+
if cached:
|
|
62
|
+
self.cache()
|
|
58
63
|
|
|
59
64
|
def __repr__(self):
|
|
60
65
|
return f"GF(2^{self.degree})"
|
|
@@ -115,6 +120,8 @@ class GF2:
|
|
|
115
120
|
|
|
116
121
|
def generator(self) -> int | None:
|
|
117
122
|
"Return a generator of the group GF(2^n)^*."
|
|
123
|
+
if self.cached:
|
|
124
|
+
return self.exp[1]
|
|
118
125
|
if self.degree == 1:
|
|
119
126
|
return self.one()
|
|
120
127
|
for a in range(2, self.order):
|
|
@@ -143,6 +150,20 @@ class GF2:
|
|
|
143
150
|
return Poly(coeff + [1])
|
|
144
151
|
return Poly(list(reversed(coeff)))
|
|
145
152
|
|
|
153
|
+
def cache(self) -> None:
|
|
154
|
+
"Create a exp/log table to speed up multiplication."
|
|
155
|
+
if not self.cached:
|
|
156
|
+
self.exp = [ 0 ] * self.mult_order
|
|
157
|
+
self.log = [ 0 ] * self.order
|
|
158
|
+
g = self.generator()
|
|
159
|
+
gj = self.one()
|
|
160
|
+
for j in range(self.mult_order):
|
|
161
|
+
self.exp[j] = gj
|
|
162
|
+
self.log[gj.x] = j
|
|
163
|
+
gj *= g
|
|
164
|
+
self.cached = True
|
|
165
|
+
|
|
166
|
+
|
|
146
167
|
class GF2nPoint:
|
|
147
168
|
"Represents a point in the Galois field GF(2^n)."
|
|
148
169
|
|
|
@@ -174,8 +195,8 @@ class GF2nPoint:
|
|
|
174
195
|
coeff = [int(d) for d in str(
|
|
175
196
|
format(self.x, "0" + str(self.field.degree) + "b"))]
|
|
176
197
|
if self.field.bitreversed:
|
|
177
|
-
|
|
178
|
-
return
|
|
198
|
+
coeff.reverse()
|
|
199
|
+
return coeff
|
|
179
200
|
|
|
180
201
|
def poly(self) -> "Poly":
|
|
181
202
|
"Convert to a polynomial."
|
|
@@ -217,7 +238,11 @@ class GF2nPoint:
|
|
|
217
238
|
if not isinstance(other, self.__class__):
|
|
218
239
|
return NotImplemented
|
|
219
240
|
if self.field != other.field:
|
|
220
|
-
raise NotImplementedError("Cannot
|
|
241
|
+
raise NotImplementedError("Cannot multiply elements from different fields.")
|
|
242
|
+
if self.field.cached:
|
|
243
|
+
if self.x and other.x:
|
|
244
|
+
return self.field.exp[(self.field.log[self.x] + self.field.log[other.x]) % self.field.mult_order]
|
|
245
|
+
return self.field.zero()
|
|
221
246
|
z = 0
|
|
222
247
|
y = other.x
|
|
223
248
|
if self.field.bitreversed:
|
|
@@ -260,12 +285,16 @@ class GF2nPoint:
|
|
|
260
285
|
def __pow__(self, j: int) -> "GF2nPoint":
|
|
261
286
|
if not isinstance(j, int):
|
|
262
287
|
return NotImplemented
|
|
263
|
-
if
|
|
264
|
-
|
|
265
|
-
|
|
288
|
+
if self.x == 0:
|
|
289
|
+
if j < 0:
|
|
290
|
+
raise ValueError("Division by zero.")
|
|
291
|
+
if j:
|
|
292
|
+
return self
|
|
293
|
+
return self.field.one()
|
|
294
|
+
j %= self.field.mult_order
|
|
295
|
+
if self.field.cached:
|
|
296
|
+
return self.field.exp[j * self.field.log[self.x] % self.field.mult_order]
|
|
266
297
|
if self.field.order == 2:
|
|
267
|
-
if j == 0:
|
|
268
|
-
return self.field.one()
|
|
269
298
|
return self
|
|
270
299
|
if self.field.bitreversed:
|
|
271
300
|
res = self.__class__(self.field.order >> 1, self.field)
|
|
@@ -341,7 +370,7 @@ class GF2nPoint:
|
|
|
341
370
|
raise ValueError("sbox is only availaible for AES/MiniAES field.")
|
|
342
371
|
|
|
343
372
|
# sbox for AES
|
|
344
|
-
GF2_aes = GF2(8, 0b100011011) # x^8 + x^4 + x^3 + x + 1 = AES
|
|
373
|
+
GF2_aes = GF2(8, 0b100011011, cached = True) # x^8 + x^4 + x^3 + x + 1 = AES
|
|
345
374
|
|
|
346
375
|
aes_sbox = [99, 124, 119, 123, 242, 107, 111, 197, 48, 1, 103, 43, 254, 215, 171, 118,
|
|
347
376
|
202, 130, 201, 125, 250, 89, 71, 240, 173, 212, 162, 175, 156, 164, 114, 192,
|
|
@@ -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.
|
|
8
|
+
__version__ = "1.7"
|
|
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
|
|
@@ -14,12 +14,12 @@ from .intfuncs import iroot, ilog, perfect_square, perfect_power, prime_power
|
|
|
14
14
|
from .factor import factorint, divisors
|
|
15
15
|
from .dlp import dlog
|
|
16
16
|
from .ec import EC_Weierstrass
|
|
17
|
-
from .la import Matrix, zeros, eye
|
|
17
|
+
from .la import Matrix, zeros, eye, circulant, BinaryMatrix
|
|
18
18
|
from .lat import gram_det, hadamard_ratio, hermite_nf, gram_schmidt, babai_round_cvp, babai_round_bnd, babai_plane_cvp, babai_plane_bnd, lagrange_lr, lll, random_unimodular_matrix
|
|
19
|
-
from .poly import Poly, lagrange_interpolation
|
|
19
|
+
from .poly import Poly, PolyBinMult, lagrange_interpolation
|
|
20
20
|
from .Zmod import Zmod
|
|
21
21
|
from .GF2 import GF2, GF2_aes, GF2_miniaes, GF2_ghash
|
|
22
|
-
from .code import gen2pchk, hamming_dist,
|
|
22
|
+
from .code import gen2pchk, hamming_dist, BinaryCode, GolayCode, HammingCode, ReedMullerCode, GoppaCode, CyclicCode, ReedSolomonCode, BCHCode
|
|
23
23
|
from .blockcipher import BlockCipher, bytexor
|
|
24
24
|
from .aes import AESKeySchedule, AESCipher, AESBlockCipher
|
|
25
25
|
from .des import list2int, int2list, permute, invert_permutation, rotate_left, SDESKeySchedule, SDESCipher, DESKeySchedule, DESCipher, DESBlockCipher
|