passphera-core 0.32.2__py3-none-any.whl → 0.33.0__py3-none-any.whl
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.
- passphera_core/entities.py +13 -44
- passphera_core/utilities.py +21 -0
- {passphera_core-0.32.2.dist-info → passphera_core-0.33.0.dist-info}/METADATA +1 -1
- passphera_core-0.33.0.dist-info/RECORD +9 -0
- passphera_core-0.32.2.dist-info/RECORD +0 -9
- {passphera_core-0.32.2.dist-info → passphera_core-0.33.0.dist-info}/WHEEL +0 -0
- {passphera_core-0.32.2.dist-info → passphera_core-0.33.0.dist-info}/licenses/LICENSE +0 -0
- {passphera_core-0.32.2.dist-info → passphera_core-0.33.0.dist-info}/top_level.txt +0 -0
passphera_core/entities.py
CHANGED
|
@@ -1,34 +1,21 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
|
|
3
|
-
from cipherspy.cipher import
|
|
3
|
+
from cipherspy.cipher import (
|
|
4
|
+
BaseCipherAlgorithm,
|
|
5
|
+
AffineCipherAlgorithm)
|
|
4
6
|
from cipherspy.exceptions import InvalidAlgorithmException
|
|
5
7
|
|
|
6
|
-
from passphera_core.utilities import check_property_name
|
|
7
|
-
|
|
8
|
-
_cipher_registry: dict = {
|
|
9
|
-
'caesar': CaesarCipherAlgorithm,
|
|
10
|
-
'affine': AffineCipherAlgorithm,
|
|
11
|
-
'playfair': PlayfairCipherAlgorithm,
|
|
12
|
-
'hill': HillCipherAlgorithm,
|
|
13
|
-
}
|
|
14
|
-
_default_properties: dict[str, object] = {
|
|
15
|
-
"shift": 3,
|
|
16
|
-
"multiplier": 3,
|
|
17
|
-
"key": "hill",
|
|
18
|
-
"algorithm": "hill",
|
|
19
|
-
"prefix": "secret",
|
|
20
|
-
"postfix": "secret"
|
|
21
|
-
}
|
|
8
|
+
from passphera_core.utilities import check_property_name, default_properties, cipher_registry
|
|
22
9
|
|
|
23
10
|
|
|
24
11
|
@dataclass
|
|
25
12
|
class Generator:
|
|
26
|
-
shift: int = field(default=
|
|
27
|
-
multiplier: int = field(default=
|
|
28
|
-
key: str = field(default=
|
|
29
|
-
algorithm: str = field(default=
|
|
30
|
-
prefix: str = field(default=
|
|
31
|
-
postfix: str = field(default=
|
|
13
|
+
shift: int = field(default=default_properties["shift"])
|
|
14
|
+
multiplier: int = field(default=default_properties["multiplier"])
|
|
15
|
+
key: str = field(default=default_properties["key"])
|
|
16
|
+
algorithm: str = field(default=default_properties["algorithm"])
|
|
17
|
+
prefix: str = field(default=default_properties["prefix"])
|
|
18
|
+
postfix: str = field(default=default_properties["postfix"])
|
|
32
19
|
characters_replacements: dict[str, str] = field(default_factory=dict[str, str])
|
|
33
20
|
|
|
34
21
|
def get_algorithm(self) -> BaseCipherAlgorithm:
|
|
@@ -37,9 +24,9 @@ class Generator:
|
|
|
37
24
|
:return: BaseCipherAlgorithm: The primary algorithm used for the cipher
|
|
38
25
|
"""
|
|
39
26
|
algo_name = self.algorithm.lower()
|
|
40
|
-
if algo_name not in
|
|
27
|
+
if algo_name not in cipher_registry:
|
|
41
28
|
raise InvalidAlgorithmException(self.algorithm)
|
|
42
|
-
AlgoClass =
|
|
29
|
+
AlgoClass = cipher_registry[algo_name]
|
|
43
30
|
if algo_name == "caesar":
|
|
44
31
|
return AlgoClass(self.shift)
|
|
45
32
|
elif algo_name == "affine":
|
|
@@ -105,7 +92,7 @@ class Generator:
|
|
|
105
92
|
:raises ValueError: If the property name is not one of the allowed properties
|
|
106
93
|
:return: None
|
|
107
94
|
"""
|
|
108
|
-
setattr(self, prop,
|
|
95
|
+
setattr(self, prop, default_properties[prop])
|
|
109
96
|
if prop == "algorithm":
|
|
110
97
|
self.get_algorithm()
|
|
111
98
|
|
|
@@ -148,21 +135,3 @@ class Generator:
|
|
|
148
135
|
for char, repl in self.characters_replacements.items():
|
|
149
136
|
password = password.replace(char, repl)
|
|
150
137
|
return ''.join(c.upper() if c in text else c for c in password)
|
|
151
|
-
|
|
152
|
-
def to_dict(self) -> dict:
|
|
153
|
-
"""Convert the Generator entity to a dictionary."""
|
|
154
|
-
return {
|
|
155
|
-
"shift": self.shift,
|
|
156
|
-
"multiplier": self.multiplier,
|
|
157
|
-
"key": self.key,
|
|
158
|
-
"algorithm": self.algorithm,
|
|
159
|
-
"prefix": self.prefix,
|
|
160
|
-
"postfix": self.postfix,
|
|
161
|
-
"character_replacements": self.characters_replacements,
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
def from_dict(self, data: dict) -> None:
|
|
165
|
-
"""Convert a dictionary to a Generator entity."""
|
|
166
|
-
for key, value in data.items():
|
|
167
|
-
if key in _default_properties or key == "characters_replacements":
|
|
168
|
-
setattr(self, key, value)
|
passphera_core/utilities.py
CHANGED
|
@@ -1,6 +1,27 @@
|
|
|
1
|
+
from cipherspy.cipher import (
|
|
2
|
+
CaesarCipherAlgorithm,
|
|
3
|
+
AffineCipherAlgorithm,
|
|
4
|
+
PlayfairCipherAlgorithm,
|
|
5
|
+
HillCipherAlgorithm)
|
|
1
6
|
from passphera_core.exceptions import InvalidPropertyNameException
|
|
2
7
|
|
|
3
8
|
|
|
9
|
+
cipher_registry: dict = {
|
|
10
|
+
'caesar': CaesarCipherAlgorithm,
|
|
11
|
+
'affine': AffineCipherAlgorithm,
|
|
12
|
+
'playfair': PlayfairCipherAlgorithm,
|
|
13
|
+
'hill': HillCipherAlgorithm,
|
|
14
|
+
}
|
|
15
|
+
default_properties: dict[str, object] = {
|
|
16
|
+
"shift": 3,
|
|
17
|
+
"multiplier": 3,
|
|
18
|
+
"key": "hill",
|
|
19
|
+
"algorithm": "hill",
|
|
20
|
+
"prefix": "secret",
|
|
21
|
+
"postfix": "secret"
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
4
25
|
def check_property_name(func):
|
|
5
26
|
def wrapper(self, prop, *args, **kwargs):
|
|
6
27
|
if prop not in {"shift", "multiplier", "key", "algorithm", "prefix", "postfix", "character_replacements"}:
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
passphera_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
passphera_core/entities.py,sha256=2QrjC3F8T5-1STSKvZndM0uY02yNhggk7pI_RLrcoYY,5904
|
|
3
|
+
passphera_core/exceptions.py,sha256=nb0iWLaFpFHEUjCa5dQ8UnIn3tZs8gN5dy2URgqJf0g,211
|
|
4
|
+
passphera_core/utilities.py,sha256=2D4xbqfIqRV5TQJn7DK5L-EwMEfp04lO9kAVqGYF3G4,872
|
|
5
|
+
passphera_core-0.33.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
passphera_core-0.33.0.dist-info/METADATA,sha256=iKq_Sm1aPbfNoJM3cVNm2o4X5GtJKxBRtQSiyEIL2lY,907
|
|
7
|
+
passphera_core-0.33.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
passphera_core-0.33.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
|
9
|
+
passphera_core-0.33.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
passphera_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
passphera_core/entities.py,sha256=LzYn3f1Ul6J2eqNRqAtpVz2H6imFEsZ1cmW4QOlVS5s,6846
|
|
3
|
-
passphera_core/exceptions.py,sha256=nb0iWLaFpFHEUjCa5dQ8UnIn3tZs8gN5dy2URgqJf0g,211
|
|
4
|
-
passphera_core/utilities.py,sha256=2cu6qWu3iseCejStxk4vD35bhQfgvb1WWx0DzXEMp_w,382
|
|
5
|
-
passphera_core-0.32.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
-
passphera_core-0.32.2.dist-info/METADATA,sha256=DyqZMCDhqb8dRqflNy3iZ4_CtgRoIZADS6pr6ZIhDNo,907
|
|
7
|
-
passphera_core-0.32.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
passphera_core-0.32.2.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
|
9
|
-
passphera_core-0.32.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|