passphera-core 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- passphera_core/__init__.py +130 -16
- {passphera_core-0.1.0.dist-info → passphera_core-0.2.0.dist-info}/METADATA +1 -1
- passphera_core-0.2.0.dist-info/RECORD +5 -0
- passphera_core-0.1.0.dist-info/RECORD +0 -5
- {passphera_core-0.1.0.dist-info → passphera_core-0.2.0.dist-info}/WHEEL +0 -0
- {passphera_core-0.1.0.dist-info → passphera_core-0.2.0.dist-info}/top_level.txt +0 -0
passphera_core/__init__.py
CHANGED
@@ -7,6 +7,9 @@ class InvalidAlgorithmException(Exception):
|
|
7
7
|
|
8
8
|
|
9
9
|
class PasswordGenerator:
|
10
|
+
"""
|
11
|
+
A strong password generator use multiple cipher algorithms to cipher a given plain text
|
12
|
+
"""
|
10
13
|
def __init__(
|
11
14
|
self,
|
12
15
|
text: str = None,
|
@@ -16,7 +19,15 @@ class PasswordGenerator:
|
|
16
19
|
key_iter: iter = (9, 4, 5, 7),
|
17
20
|
algorithm: str = 'playfair'
|
18
21
|
):
|
19
|
-
|
22
|
+
"""
|
23
|
+
:param text: plain text to be ciphered
|
24
|
+
:param shift: number of characters to shift each character (default 3)
|
25
|
+
:param multiplier: number of characters to shift each character (default 3)
|
26
|
+
:param key_str: cipher key string (default "secret")
|
27
|
+
:param key_iter: cipher key matrix (default (9, 4, 5, 7))
|
28
|
+
:param algorithm: main cipher algorithm name (default 'playfair')
|
29
|
+
"""
|
30
|
+
self._chars_replacements: dict = {}
|
20
31
|
self._text: str = text
|
21
32
|
self._shift: int = shift
|
22
33
|
self._multiplier: int = multiplier
|
@@ -24,61 +35,138 @@ class PasswordGenerator:
|
|
24
35
|
self._key_iter: iter = key_iter
|
25
36
|
self._algorithm_name: str = algorithm.lower()
|
26
37
|
self._algorithm = self._set_algorithm()
|
38
|
+
self._password: str = f'secret{self._text}secret'
|
27
39
|
|
28
40
|
@property
|
29
41
|
def text(self) -> str:
|
42
|
+
"""
|
43
|
+
Returns the text to be ciphered into a password
|
44
|
+
Eg: ```password = pg.text```
|
45
|
+
:return: str: The text to be ciphered into a password
|
46
|
+
"""
|
30
47
|
return self._text
|
31
48
|
|
32
49
|
@text.setter
|
33
50
|
def text(self, text: str) -> None:
|
51
|
+
"""
|
52
|
+
Sets the text to be ciphered into a password
|
53
|
+
Eg: ```pg.text = 'secret 2024 password'```
|
54
|
+
:param text: The text to be ciphered into a password
|
55
|
+
:return:
|
56
|
+
"""
|
34
57
|
self._text = text
|
58
|
+
self._password: str = f'secret{self._text}secret'
|
35
59
|
|
36
60
|
@property
|
37
61
|
def shift(self) -> int:
|
62
|
+
"""
|
63
|
+
Returns the shift value for the cipher algorithm
|
64
|
+
Eg: ```shift = pg.shift```
|
65
|
+
:return: int: The shift value for the cipher algorithm
|
66
|
+
"""
|
38
67
|
return self._shift
|
39
68
|
|
40
69
|
@shift.setter
|
41
70
|
def shift(self, shift: int) -> None:
|
71
|
+
"""
|
72
|
+
Sets the shift value for the cipher algorithm
|
73
|
+
Eg: ```pg.shift = 3```
|
74
|
+
:param shift: The shift value for the cipher algorithm
|
75
|
+
:return:
|
76
|
+
"""
|
42
77
|
self._shift = shift
|
43
78
|
|
44
79
|
@property
|
45
80
|
def multiplier(self) -> int:
|
81
|
+
"""
|
82
|
+
Returns the multiplier value for the cipher algorithm
|
83
|
+
Eg: ```multiplier = pg.multiplier```
|
84
|
+
:return: int: The multiplier value for the cipher algorithm
|
85
|
+
"""
|
46
86
|
return self._multiplier
|
47
87
|
|
48
88
|
@multiplier.setter
|
49
89
|
def multiplier(self, multiplier: int) -> None:
|
90
|
+
"""
|
91
|
+
Sets the multiplier value for the cipher algorithm
|
92
|
+
Eg: ```pg.multiplier = 3```
|
93
|
+
:param multiplier: The multiplier value for the cipher algorithm
|
94
|
+
:return:
|
95
|
+
"""
|
50
96
|
self._multiplier = multiplier
|
51
97
|
|
52
98
|
@property
|
53
99
|
def key_str(self) -> str:
|
100
|
+
"""
|
101
|
+
Returns the key string for the cipher algorithm
|
102
|
+
Eg: ```key_str = pg.key_str```
|
103
|
+
:return: str: The key string for the cipher algorithm
|
104
|
+
"""
|
54
105
|
return self._key_str
|
55
106
|
|
56
107
|
@key_str.setter
|
57
108
|
def key_str(self, key_str: str) -> None:
|
109
|
+
"""
|
110
|
+
Sets the key string for the cipher algorithm
|
111
|
+
Eg: ```pg.key_str = 'secret key'```
|
112
|
+
:param key_str: The key string for the cipher algorithm
|
113
|
+
:return:
|
114
|
+
"""
|
58
115
|
self._key_str = key_str
|
59
116
|
|
60
117
|
@property
|
61
118
|
def key_iter(self) -> iter:
|
119
|
+
"""
|
120
|
+
Returns the key matrix for the cipher algorithm
|
121
|
+
Eg: ```key_iter = pg.key_iter```
|
122
|
+
:return: iter: The key matrix for the cipher algorithm
|
123
|
+
"""
|
62
124
|
return self._key_iter
|
63
125
|
|
64
126
|
@key_iter.setter
|
65
127
|
def key_iter(self, key_iter: iter) -> None:
|
128
|
+
"""
|
129
|
+
Sets the key matrix for the cipher algorithm
|
130
|
+
Eg: ```pg.key_iter = (9, 5, 2, 4)```
|
131
|
+
:param key_iter: The key matrix for the cipher algorithm
|
132
|
+
:return:
|
133
|
+
"""
|
66
134
|
self._key_iter = key_iter
|
67
135
|
|
68
136
|
@property
|
69
137
|
def algorithm(self) -> str:
|
138
|
+
"""
|
139
|
+
Returns the main cipher algorithm name
|
140
|
+
Eg: ```algorithm = pg.algorithm```
|
141
|
+
:return: str: The main cipher algorithm name
|
142
|
+
"""
|
70
143
|
return self._algorithm_name
|
71
144
|
|
72
145
|
@algorithm.setter
|
73
146
|
def algorithm(self, algorithm: str) -> None:
|
147
|
+
"""
|
148
|
+
Sets the main cipher algorithm
|
149
|
+
Eg: ```pg.algorithm = 'playfair'```
|
150
|
+
:param algorithm: The name of the main cipher algorithm
|
151
|
+
:return:
|
152
|
+
"""
|
74
153
|
self._algorithm_name = algorithm.lower()
|
75
154
|
self._algorithm = self._set_algorithm()
|
76
155
|
|
77
156
|
@property
|
78
|
-
def
|
79
|
-
|
157
|
+
def characters_replacements(self) -> dict:
|
158
|
+
"""
|
159
|
+
Returns the dictionary of the characters replacements
|
160
|
+
Eg: ```print(pg.characters_replacements) # {'a': '@1', 'b': '#2'}```
|
161
|
+
:return: dict: The dictionary of the characters replacements
|
162
|
+
"""
|
163
|
+
return self._chars_replacements
|
80
164
|
|
81
165
|
def _set_algorithm(self):
|
166
|
+
"""
|
167
|
+
Return new instance of the used algorithm to the given one by it's name
|
168
|
+
:return: new algorithm class
|
169
|
+
"""
|
82
170
|
match self._algorithm_name:
|
83
171
|
case 'caesar':
|
84
172
|
return CaesarCipher(self._shift)
|
@@ -92,26 +180,52 @@ class PasswordGenerator:
|
|
92
180
|
raise InvalidAlgorithmException(self._algorithm_name)
|
93
181
|
|
94
182
|
def _update_algorithm_properties(self) -> None:
|
183
|
+
"""
|
184
|
+
Update the main cipher algorithm
|
185
|
+
"""
|
95
186
|
self._algorithm = self._set_algorithm()
|
96
187
|
|
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
188
|
def replace_character(self, char: str, replacement: str) -> None:
|
106
|
-
|
189
|
+
"""
|
190
|
+
Replace a character with another character or set of characters
|
191
|
+
Eg: pg.replace_character('a', '@1')
|
192
|
+
:param char: The character to be replaced
|
193
|
+
:param replacement: The (character|set of characters) to replace the first one
|
194
|
+
:return:
|
195
|
+
"""
|
196
|
+
self._chars_replacements[char[0]] = replacement
|
107
197
|
|
108
198
|
def reset_character(self, char: str) -> None:
|
109
|
-
|
110
|
-
|
199
|
+
"""
|
200
|
+
Reset a character to it's original value (remove it's replacement from characters_replacements)
|
201
|
+
:param char: The character to be reset to its original value
|
202
|
+
:return:
|
203
|
+
"""
|
204
|
+
if char in self._chars_replacements:
|
205
|
+
del self._chars_replacements[char]
|
111
206
|
|
112
207
|
def generate_raw_password(self) -> str:
|
208
|
+
"""
|
209
|
+
Generate a raw password string using the given parameters
|
210
|
+
:return: str: The generated raw password
|
211
|
+
"""
|
113
212
|
self._update_algorithm_properties()
|
114
|
-
return self._algorithm.encrypt(self.
|
213
|
+
return self._algorithm.encrypt(self._password)
|
115
214
|
|
116
215
|
def generate_password(self) -> str:
|
117
|
-
|
216
|
+
"""
|
217
|
+
Generate a strong password string using the raw password (add another layer of encryption to it)
|
218
|
+
:return: str: The generated strong password
|
219
|
+
"""
|
220
|
+
old_algorithm = self._algorithm_name
|
221
|
+
self._algorithm_name = 'affine'
|
222
|
+
self._update_algorithm_properties()
|
223
|
+
self._password = self.generate_raw_password()
|
224
|
+
self._algorithm_name = old_algorithm
|
225
|
+
self._update_algorithm_properties()
|
226
|
+
for char, replacement in self._chars_replacements.items():
|
227
|
+
self._password = self._password.replace(char, replacement)
|
228
|
+
for char in self._password:
|
229
|
+
if char in self._text:
|
230
|
+
self._password = self._text.replace(char, char.upper())
|
231
|
+
return self._password
|
@@ -0,0 +1,5 @@
|
|
1
|
+
passphera_core/__init__.py,sha256=-uEZjnBgHVJIjvJD0xmtQBgnlv5VoqAfunTuqyCFnqI,7845
|
2
|
+
passphera_core-0.2.0.dist-info/METADATA,sha256=Kp_AjT4fJWdbVqWoP4eA85bkmJUtsVMGpC-aAGJA0uA,627
|
3
|
+
passphera_core-0.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
4
|
+
passphera_core-0.2.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
5
|
+
passphera_core-0.2.0.dist-info/RECORD,,
|
@@ -1,5 +0,0 @@
|
|
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,,
|
File without changes
|
File without changes
|