kryptools 1.0__tar.gz → 1.0.1__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.0 → kryptools-1.0.1}/PKG-INFO +1 -1
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/__init__.py +1 -1
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/des.py +12 -2
- {kryptools-1.0 → kryptools-1.0.1}/kryptools.egg-info/PKG-INFO +1 -1
- {kryptools-1.0 → kryptools-1.0.1}/pyproject.toml +1 -1
- kryptools-1.0.1/tests/test_des.py +59 -0
- kryptools-1.0/tests/test_des.py +0 -42
- {kryptools-1.0 → kryptools-1.0.1}/LICENSE +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/README.md +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/GF2.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/Zmod.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/aes.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/blockcipher.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/conway_polynomials.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/dlp.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/dlp_bsgs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/dlp_ic.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/dlp_qs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/dlp_rho.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/ec.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_dix.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_ecm.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_fmt.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_pm1.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_qs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/factor_rho.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/intfuncs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/la.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/lat.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/nt.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/poly.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools/primes.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools.egg-info/SOURCES.txt +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools.egg-info/dependency_links.txt +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/kryptools.egg-info/top_level.txt +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/setup.cfg +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_GF2.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_Zmod.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_aes.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_dlog.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_ec.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_factor.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_factor_fmt.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_factor_pm1.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_factor_qs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_intfuncs.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_la.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_lat.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_nt.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_poly.py +0 -0
- {kryptools-1.0 → kryptools-1.0.1}/tests/test_primes.py +0 -0
|
@@ -5,7 +5,7 @@ Implemenation of same basic algorithms used in cryptography.
|
|
|
5
5
|
__author__ = "Gerald Teschl"
|
|
6
6
|
__copyright__ = "Copyright 2024, Gerald Teschl"
|
|
7
7
|
__license__ = "MIT License"
|
|
8
|
-
__version__ = "0.
|
|
8
|
+
__version__ = "1.0.1"
|
|
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
|
|
@@ -151,10 +151,18 @@ class FeistelCipher:
|
|
|
151
151
|
"Switch left and right halves"
|
|
152
152
|
self.state = self.right() + self.left()
|
|
153
153
|
|
|
154
|
-
def f_box(self, a: list[int], key: list[int]) -> list[int]:
|
|
154
|
+
def f_box(self, a: list[int], key: list[int], showtmp:bool = False) -> list[int]:
|
|
155
155
|
"Nonlinear f-box"
|
|
156
|
+
if showtmp:
|
|
157
|
+
def printtmp(title:str, a: list) -> None:
|
|
158
|
+
print(f"{title}: {"".join(map(str,a))}")
|
|
159
|
+
else:
|
|
160
|
+
def printtmp(title:str, a: list) -> None:
|
|
161
|
+
pass
|
|
156
162
|
a = permute(a, self.__class__.E_box) # expansion box
|
|
163
|
+
printtmp("EBox", a)
|
|
157
164
|
a = self.xor(a, key) # add key
|
|
165
|
+
printtmp("XKey", a)
|
|
158
166
|
split = len(self.__class__.S_split)
|
|
159
167
|
# apply sboxes
|
|
160
168
|
num_sbox = len(self.__class__.S_box) # number of sboxes
|
|
@@ -168,7 +176,9 @@ class FeistelCipher:
|
|
|
168
176
|
s = self.__class__.S_box[i][index]
|
|
169
177
|
aa += [int(d) for d in str(format(s, "0" + str(out_len) + "b"))]
|
|
170
178
|
a = aa
|
|
179
|
+
printtmp("SBox", a)
|
|
171
180
|
a = permute(a, self.__class__.P_box) # permutation box
|
|
181
|
+
printtmp("PBox", a)
|
|
172
182
|
return a
|
|
173
183
|
|
|
174
184
|
def ip(self) -> None:
|
|
@@ -298,7 +308,7 @@ class DESCipher(FeistelCipher):
|
|
|
298
308
|
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
|
|
299
309
|
4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
|
|
300
310
|
15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13),
|
|
301
|
-
(15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5,
|
|
311
|
+
(15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
|
|
302
312
|
3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
|
|
303
313
|
0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
|
|
304
314
|
13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9),
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from kryptools import SDESKeySchedule, SDESCipher, DESKeySchedule, DESCipher, list2int
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def test_SDES():
|
|
6
|
+
# Test the key schedule
|
|
7
|
+
key = 34
|
|
8
|
+
test_values = [[0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0]]
|
|
9
|
+
|
|
10
|
+
ks = SDESKeySchedule(key)
|
|
11
|
+
assert ks.gen_keys() == test_values
|
|
12
|
+
|
|
13
|
+
# Test the encryption
|
|
14
|
+
x = b'\x01'
|
|
15
|
+
y = b'\xb9'
|
|
16
|
+
|
|
17
|
+
sdes = SDESCipher(key)
|
|
18
|
+
sdes(x).encrypt()
|
|
19
|
+
assert bytes(sdes) == y
|
|
20
|
+
assert sdes.decrypt() == x
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_DES():
|
|
24
|
+
# Test the key schedule
|
|
25
|
+
key = 0x0123456789ABCDEF.to_bytes(8, 'big')
|
|
26
|
+
test_values = [0x0B02679B49A5, 0x69A659256A26, 0x45D48AB428D2, 0x7289D2A58257, 0x3CE80317A6C2, 0x23251E3C8545, 0x6C04950AE4C6, 0x5788386CE581,
|
|
27
|
+
0xC0C9E926B839, 0x91E307631D72, 0x211F830D893A, 0x7130E5455C54, 0x91C4D04980FC, 0x5443B681DC8D, 0xB691050A16B5, 0xCA3D03B87032]
|
|
28
|
+
|
|
29
|
+
ks = DESKeySchedule(key)
|
|
30
|
+
keys = ks.gen_keys()
|
|
31
|
+
for k1, k2 in zip(keys, test_values):
|
|
32
|
+
assert list2int(k1) == k2
|
|
33
|
+
|
|
34
|
+
# Test the encryption (Handbook of Applied Cryptography and NBS Special Publication 500-20)
|
|
35
|
+
test_values = [[ 0x0123456789ABCDEF, 0x4E6F772069732074, 0x3FA40E8A984D4815 ],
|
|
36
|
+
[0x10316E028C8F3B4A, 0x0000000000000000, 0x82DCBAFBDEAB6602],
|
|
37
|
+
[0x0101010101010101, 0x95F8A5E5DD31D900, 0x8000000000000000],
|
|
38
|
+
[0x0101010101010101, 0xDD7F121CA5015619, 0x4000000000000000],
|
|
39
|
+
[0x0101010101010101, 0x2E8653104F3834EA, 0x2000000000000000],
|
|
40
|
+
[0x0101010101010101, 0x4BD388FF6CD81D4F, 0x1000000000000000],
|
|
41
|
+
[0x0101010101010101, 0x20B9E767B2FB1456, 0x0800000000000000],
|
|
42
|
+
[0x0101010101010101, 0x8000000000000000, 0x95F8A5E5DD31D900],
|
|
43
|
+
[0x0101010101010101, 0x4000000000000000, 0xDD7F121CA5015619],
|
|
44
|
+
[0x0101010101010101, 0x2000000000000000, 0x2E8653104F3834EA],
|
|
45
|
+
[0x0101010101010101, 0x1000000000000000, 0x4BD388FF6CD81D4F],
|
|
46
|
+
[0x8001010101010101, 0x0000000000000000, 0x95A8D72813DAA94D],
|
|
47
|
+
[0x4001010101010101, 0x0000000000000000, 0x0EEC1487DD8C26D5],
|
|
48
|
+
[0x2001010101010101, 0x0000000000000000, 0x7AD16FFB79C45926],
|
|
49
|
+
[0x1001010101010101, 0x0000000000000000, 0xD3746294CA6A6CF3]]
|
|
50
|
+
|
|
51
|
+
for key, x, y in test_values:
|
|
52
|
+
key = key.to_bytes(8, 'big')
|
|
53
|
+
x = x.to_bytes(8, 'big')
|
|
54
|
+
y = y.to_bytes(8, 'big')
|
|
55
|
+
|
|
56
|
+
des = DESCipher(key)
|
|
57
|
+
des(x).encrypt()
|
|
58
|
+
assert bytes(des) == y
|
|
59
|
+
assert des.decrypt() == x
|
kryptools-1.0/tests/test_des.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import pytest
|
|
2
|
-
from kryptools import SDESKeySchedule, SDESCipher, DESKeySchedule, DESCipher, list2int
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def test_SDES():
|
|
6
|
-
# Test the key schedule
|
|
7
|
-
key = 34
|
|
8
|
-
test_values = [[0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 1, 0]]
|
|
9
|
-
|
|
10
|
-
ks = SDESKeySchedule(key)
|
|
11
|
-
assert ks.gen_keys() == test_values
|
|
12
|
-
|
|
13
|
-
# Test the encryption
|
|
14
|
-
x = b'\x01'
|
|
15
|
-
y = b'\xb9'
|
|
16
|
-
|
|
17
|
-
sdes = SDESCipher(key)
|
|
18
|
-
sdes(x).encrypt()
|
|
19
|
-
assert bytes(sdes) == y
|
|
20
|
-
assert sdes.decrypt() == x
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def test_DES():
|
|
24
|
-
# Test the key schedule
|
|
25
|
-
key = 0x0123456789ABCDEF.to_bytes(8, 'big')
|
|
26
|
-
test_values = [0x0B02679B49A5, 0x69A659256A26, 0x45D48AB428D2, 0x7289D2A58257, 0x3CE80317A6C2, 0x23251E3C8545, 0x6C04950AE4C6, 0x5788386CE581,
|
|
27
|
-
0xC0C9E926B839, 0x91E307631D72, 0x211F830D893A, 0x7130E5455C54, 0x91C4D04980FC, 0x5443B681DC8D, 0xB691050A16B5, 0xCA3D03B87032]
|
|
28
|
-
|
|
29
|
-
ks = DESKeySchedule(key)
|
|
30
|
-
keys = ks.gen_keys()
|
|
31
|
-
for k1, k2 in zip(keys, test_values):
|
|
32
|
-
assert list2int(k1) == k2
|
|
33
|
-
|
|
34
|
-
# Test the encryption (Handbook of Applied Cryptography)
|
|
35
|
-
key = 0x0123456789ABCDEF.to_bytes(8, 'big')
|
|
36
|
-
x = 0x4E6F772069732074.to_bytes(8, 'big')
|
|
37
|
-
y = 0x3FA40E8A984D4815.to_bytes(8, 'big')
|
|
38
|
-
|
|
39
|
-
des = DESCipher(key)
|
|
40
|
-
des(x).encrypt()
|
|
41
|
-
assert bytes(des) == y
|
|
42
|
-
assert des.decrypt() == x
|
|
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
|