passphera-core 0.1.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,117 @@
|
|
1
|
+
from cipherspy.cipher import *
|
2
|
+
|
3
|
+
|
4
|
+
class InvalidAlgorithmException(Exception):
|
5
|
+
def __init__(self, algorithm: str) -> None:
|
6
|
+
super().__init__(f"Invalid algorithm name {algorithm}")
|
7
|
+
|
8
|
+
|
9
|
+
class PasswordGenerator:
|
10
|
+
def __init__(
|
11
|
+
self,
|
12
|
+
text: str = None,
|
13
|
+
shift: int = 3,
|
14
|
+
multiplier: int = 3,
|
15
|
+
key_str: str = "secret",
|
16
|
+
key_iter: iter = (9, 4, 5, 7),
|
17
|
+
algorithm: str = 'playfair'
|
18
|
+
):
|
19
|
+
self._char_replacements: dict = {}
|
20
|
+
self._text: str = text
|
21
|
+
self._shift: int = shift
|
22
|
+
self._multiplier: int = multiplier
|
23
|
+
self._key_str: str = key_str
|
24
|
+
self._key_iter: iter = key_iter
|
25
|
+
self._algorithm_name: str = algorithm.lower()
|
26
|
+
self._algorithm = self._set_algorithm()
|
27
|
+
|
28
|
+
@property
|
29
|
+
def text(self) -> str:
|
30
|
+
return self._text
|
31
|
+
|
32
|
+
@text.setter
|
33
|
+
def text(self, text: str) -> None:
|
34
|
+
self._text = text
|
35
|
+
|
36
|
+
@property
|
37
|
+
def shift(self) -> int:
|
38
|
+
return self._shift
|
39
|
+
|
40
|
+
@shift.setter
|
41
|
+
def shift(self, shift: int) -> None:
|
42
|
+
self._shift = shift
|
43
|
+
|
44
|
+
@property
|
45
|
+
def multiplier(self) -> int:
|
46
|
+
return self._multiplier
|
47
|
+
|
48
|
+
@multiplier.setter
|
49
|
+
def multiplier(self, multiplier: int) -> None:
|
50
|
+
self._multiplier = multiplier
|
51
|
+
|
52
|
+
@property
|
53
|
+
def key_str(self) -> str:
|
54
|
+
return self._key_str
|
55
|
+
|
56
|
+
@key_str.setter
|
57
|
+
def key_str(self, key_str: str) -> None:
|
58
|
+
self._key_str = key_str
|
59
|
+
|
60
|
+
@property
|
61
|
+
def key_iter(self) -> iter:
|
62
|
+
return self._key_iter
|
63
|
+
|
64
|
+
@key_iter.setter
|
65
|
+
def key_iter(self, key_iter: iter) -> None:
|
66
|
+
self._key_iter = key_iter
|
67
|
+
|
68
|
+
@property
|
69
|
+
def algorithm(self) -> str:
|
70
|
+
return self._algorithm_name
|
71
|
+
|
72
|
+
@algorithm.setter
|
73
|
+
def algorithm(self, algorithm: str) -> None:
|
74
|
+
self._algorithm_name = algorithm.lower()
|
75
|
+
self._algorithm = self._set_algorithm()
|
76
|
+
|
77
|
+
@property
|
78
|
+
def character_replacements(self) -> dict:
|
79
|
+
return self._char_replacements
|
80
|
+
|
81
|
+
def _set_algorithm(self):
|
82
|
+
match self._algorithm_name:
|
83
|
+
case 'caesar':
|
84
|
+
return CaesarCipher(self._shift)
|
85
|
+
case 'affine':
|
86
|
+
return AffineCipher(self._multiplier, self._shift)
|
87
|
+
case 'playfair':
|
88
|
+
return PlayfairCipher(self._key_str)
|
89
|
+
case 'hill':
|
90
|
+
return HillCipher(self._key_iter)
|
91
|
+
case _:
|
92
|
+
raise InvalidAlgorithmException(self._algorithm_name)
|
93
|
+
|
94
|
+
def _update_algorithm_properties(self) -> None:
|
95
|
+
self._algorithm = self._set_algorithm()
|
96
|
+
|
97
|
+
def _custom_cipher(self, password: str) -> str:
|
98
|
+
for char, replacement in self._char_replacements.items():
|
99
|
+
password = password.replace(char, replacement)
|
100
|
+
for i in range(len(password)):
|
101
|
+
if password[i] in self._text:
|
102
|
+
password = password.replace(password[i], password[i].upper())
|
103
|
+
return password
|
104
|
+
|
105
|
+
def replace_character(self, char: str, replacement: str) -> None:
|
106
|
+
self._char_replacements[char[0]] = replacement
|
107
|
+
|
108
|
+
def reset_character(self, char: str) -> None:
|
109
|
+
if char in self._char_replacements:
|
110
|
+
del self._char_replacements[char]
|
111
|
+
|
112
|
+
def generate_raw_password(self) -> str:
|
113
|
+
self._update_algorithm_properties()
|
114
|
+
return self._algorithm.encrypt(self._text)
|
115
|
+
|
116
|
+
def generate_password(self) -> str:
|
117
|
+
return self._custom_cipher(self.generate_raw_password())
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: passphera-core
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: The core system of passphera project
|
5
|
+
Home-page: https://github.com/passphera/core
|
6
|
+
Author: Fathi Abdelmalek
|
7
|
+
Author-email: abdelmalek.fathi.2001@gmail.com
|
8
|
+
Classifier: Development Status :: 1 - Planning
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Classifier: Programming Language :: Python
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
13
|
+
Classifier: Topic :: Security
|
14
|
+
Classifier: Topic :: Security :: Cryptography
|
15
|
+
Description-Content-Type: text/markdown
|
16
|
+
|
17
|
+
# passphera-cre
|
18
|
+
|
19
|
+
The core system of passphera project
|
@@ -0,0 +1,5 @@
|
|
1
|
+
passphera_core/__init__.py,sha256=_1eCAZI3Yjl2qVpzngz3zQIHItwfTTn_aeqZSTbRQBI,3465
|
2
|
+
passphera_core-0.1.0.dist-info/METADATA,sha256=yAiuFgI2K0HmpJjQNSZuC3YHyjFSazVLd-_tHyE5hSE,627
|
3
|
+
passphera_core-0.1.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
4
|
+
passphera_core-0.1.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
5
|
+
passphera_core-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
passphera_core
|