passphera-core 0.4.0__py3-none-any.whl → 0.6.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- passphera_core/generator.py +22 -44
- {passphera_core-0.4.0.dist-info → passphera_core-0.6.0.dist-info}/METADATA +1 -1
- passphera_core-0.6.0.dist-info/RECORD +7 -0
- passphera_core-0.4.0.dist-info/RECORD +0 -7
- {passphera_core-0.4.0.dist-info → passphera_core-0.6.0.dist-info}/WHEEL +0 -0
- {passphera_core-0.4.0.dist-info → passphera_core-0.6.0.dist-info}/top_level.txt +0 -0
passphera_core/generator.py
CHANGED
@@ -9,50 +9,28 @@ class PasswordGenerator:
|
|
9
9
|
"""
|
10
10
|
def __init__(
|
11
11
|
self,
|
12
|
-
text: str = None,
|
13
12
|
shift: int = 3,
|
14
13
|
multiplier: int = 3,
|
15
14
|
key: str = "hill",
|
16
|
-
algorithm: str = 'hill'
|
15
|
+
algorithm: str = 'hill',
|
16
|
+
characters_replacements: dict = None,
|
17
17
|
):
|
18
18
|
"""
|
19
|
-
:param text: plain text to be ciphered
|
20
19
|
:param shift: number of characters to shift each character (default 3)
|
21
20
|
:param multiplier: number of characters to shift each character (default 3)
|
22
21
|
:param key: cipher key string (default "secret")
|
23
22
|
:param algorithm: main cipher algorithm name (default 'playfair')
|
23
|
+
:param characters_replacements: replace characters with the given values (default {})
|
24
|
+
:param text: plain text to be ciphered
|
24
25
|
"""
|
25
|
-
|
26
|
-
|
26
|
+
if characters_replacements is None:
|
27
|
+
characters_replacements = {}
|
27
28
|
self._shift: int = shift
|
28
29
|
self._multiplier: int = multiplier
|
29
30
|
self._key: str = key
|
30
31
|
self._algorithm_name: str = algorithm.lower()
|
31
32
|
self._algorithm = self._set_algorithm()
|
32
|
-
|
33
|
-
self._password: str = f"secret{self._text.replace(' ', '')}secret"
|
34
|
-
else:
|
35
|
-
self._password: str = f'secret'
|
36
|
-
|
37
|
-
@property
|
38
|
-
def text(self) -> str:
|
39
|
-
"""
|
40
|
-
Returns the text to be ciphered into a password
|
41
|
-
Eg: ```password = pg.text```
|
42
|
-
:return: str: The text to be ciphered into a password
|
43
|
-
"""
|
44
|
-
return self._text
|
45
|
-
|
46
|
-
@text.setter
|
47
|
-
def text(self, text: str) -> None:
|
48
|
-
"""
|
49
|
-
Sets the text to be ciphered into a password
|
50
|
-
Eg: ```pg.text = 'secret 2024 password'```
|
51
|
-
:param text: The text to be ciphered into a password
|
52
|
-
:return:
|
53
|
-
"""
|
54
|
-
self._text = text
|
55
|
-
self._password: str = f"secret{self._text.replace(' ', '')}secret"
|
33
|
+
self._characters_replacements: dict = characters_replacements
|
56
34
|
|
57
35
|
@property
|
58
36
|
def shift(self) -> int:
|
@@ -138,7 +116,7 @@ class PasswordGenerator:
|
|
138
116
|
Eg: ```print(pg.characters_replacements) # {'a': '@1', 'b': '#2'}```
|
139
117
|
:return: dict: The dictionary of the characters replacements
|
140
118
|
"""
|
141
|
-
return self.
|
119
|
+
return self._characters_replacements
|
142
120
|
|
143
121
|
def _set_algorithm(self):
|
144
122
|
"""
|
@@ -171,7 +149,7 @@ class PasswordGenerator:
|
|
171
149
|
:param replacement: The (character|set of characters) to replace the first one
|
172
150
|
:return:
|
173
151
|
"""
|
174
|
-
self.
|
152
|
+
self._characters_replacements[char[0]] = replacement
|
175
153
|
|
176
154
|
def reset_character(self, char: str) -> None:
|
177
155
|
"""
|
@@ -179,30 +157,30 @@ class PasswordGenerator:
|
|
179
157
|
:param char: The character to be reset to its original value
|
180
158
|
:return:
|
181
159
|
"""
|
182
|
-
if char in self.
|
183
|
-
del self.
|
160
|
+
if char in self._characters_replacements:
|
161
|
+
del self._characters_replacements[char]
|
184
162
|
|
185
|
-
def generate_raw_password(self) -> str:
|
163
|
+
def generate_raw_password(self, text: str) -> str:
|
186
164
|
"""
|
187
165
|
Generate a raw password string using the given parameters
|
188
166
|
:return: str: The generated raw password
|
189
167
|
"""
|
190
168
|
self._update_algorithm_properties()
|
191
|
-
return self._algorithm.encrypt(
|
169
|
+
return self._algorithm.encrypt(f"secret{text}secret")
|
192
170
|
|
193
|
-
def generate_password(self) -> str:
|
171
|
+
def generate_password(self, text: str) -> str:
|
194
172
|
"""
|
195
173
|
Generate a strong password string using the raw password (add another layer of encryption to it)
|
196
174
|
:return: str: The generated strong password
|
197
175
|
"""
|
198
176
|
old_algorithm = self._algorithm_name
|
199
177
|
self._algorithm_name = 'affine'
|
200
|
-
|
178
|
+
password = self.generate_raw_password(text)
|
201
179
|
self._algorithm_name = old_algorithm
|
202
|
-
|
203
|
-
for char in
|
204
|
-
if char in
|
205
|
-
|
206
|
-
for char, replacement in self.
|
207
|
-
|
208
|
-
return
|
180
|
+
password = self.generate_raw_password(password)
|
181
|
+
for char in password:
|
182
|
+
if char in text:
|
183
|
+
password = password.replace(char, char.upper())
|
184
|
+
for char, replacement in self._characters_replacements.items():
|
185
|
+
password = password.replace(char, replacement)
|
186
|
+
return password
|
@@ -0,0 +1,7 @@
|
|
1
|
+
passphera_core/__init__.py,sha256=ND2D_sTQk5mroNRsKm03PXhx0HNf0740hOtZ4_U98OQ,119
|
2
|
+
passphera_core/exceptions.py,sha256=PPZhy05QMVnN3mm6EGj-RgWanMaF3E6aKN4lcpNOJY8,158
|
3
|
+
passphera_core/generator.py,sha256=s0Uc4S3SCT97xwQ0Gcw4hogGFIzTG5W0QX6Hs01iXII,6478
|
4
|
+
passphera_core-0.6.0.dist-info/METADATA,sha256=e_eLSaPhPv2kwOHyPQOyLS7RADfmTQ5ni-VBLpoJ1sU,628
|
5
|
+
passphera_core-0.6.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
+
passphera_core-0.6.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
7
|
+
passphera_core-0.6.0.dist-info/RECORD,,
|
@@ -1,7 +0,0 @@
|
|
1
|
-
passphera_core/__init__.py,sha256=ND2D_sTQk5mroNRsKm03PXhx0HNf0740hOtZ4_U98OQ,119
|
2
|
-
passphera_core/exceptions.py,sha256=PPZhy05QMVnN3mm6EGj-RgWanMaF3E6aKN4lcpNOJY8,158
|
3
|
-
passphera_core/generator.py,sha256=_OjRbToWw20nOOzBCc7kPg3DwCURK_HoTkI4Dyv7Rls,7036
|
4
|
-
passphera_core-0.4.0.dist-info/METADATA,sha256=9olDGxoeUkzJGImvwSVLwVW7bjUkXBiYwr7fC2vnfQg,628
|
5
|
-
passphera_core-0.4.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
6
|
-
passphera_core-0.4.0.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
|
7
|
-
passphera_core-0.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|