passphera-core 0.2.1__py3-none-any.whl → 0.3.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,234 +1,2 @@
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
- """
11
- A strong password generator use multiple cipher algorithms to cipher a given plain text
12
- """
13
- def __init__(
14
- self,
15
- text: str = None,
16
- shift: int = 3,
17
- multiplier: int = 3,
18
- key_str: str = "secret",
19
- key_iter: iter = (9, 4, 5, 7),
20
- algorithm: str = 'playfair'
21
- ):
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 = {}
31
- self._text: str = text
32
- self._shift: int = shift
33
- self._multiplier: int = multiplier
34
- self._key_str: str = key_str
35
- self._key_iter: iter = key_iter
36
- self._algorithm_name: str = algorithm.lower()
37
- self._algorithm = self._set_algorithm()
38
- self._password: str = f'secret{self._text}secret'
39
-
40
- @property
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
- """
47
- return self._text
48
-
49
- @text.setter
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
- """
57
- self._text = text
58
- self._password: str = f'secret{self._text}secret'
59
-
60
- @property
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
- """
67
- return self._shift
68
-
69
- @shift.setter
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
- """
77
- self._shift = shift
78
-
79
- @property
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
- """
86
- return self._multiplier
87
-
88
- @multiplier.setter
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
- """
96
- self._multiplier = multiplier
97
-
98
- @property
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
- """
105
- return self._key_str
106
-
107
- @key_str.setter
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
- """
115
- self._key_str = key_str
116
-
117
- @property
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
- """
124
- return self._key_iter
125
-
126
- @key_iter.setter
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
- """
134
- self._key_iter = key_iter
135
-
136
- @property
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
- """
143
- return self._algorithm_name
144
-
145
- @algorithm.setter
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
- """
153
- self._algorithm_name = algorithm.lower()
154
- self._algorithm = self._set_algorithm()
155
-
156
- @property
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
164
-
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
- """
170
- match self._algorithm_name:
171
- case 'caesar':
172
- return CaesarCipher(self._shift)
173
- case 'affine':
174
- return AffineCipher(self._multiplier, self._shift)
175
- case 'playfair':
176
- return PlayfairCipher(self._key_str)
177
- case 'hill':
178
- return HillCipher(self._key_iter)
179
- case _:
180
- raise InvalidAlgorithmException(self._algorithm_name)
181
-
182
- def _update_algorithm_properties(self) -> None:
183
- """
184
- Update the main cipher algorithm
185
- """
186
- self._algorithm = self._set_algorithm()
187
-
188
- def replace_character(self, char: str, replacement: str) -> None:
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
197
-
198
- def reset_character(self, char: str) -> None:
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]
206
-
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
- """
212
- self._update_algorithm_properties()
213
- return self._algorithm.encrypt(self._password)
214
-
215
- def generate_password(self) -> str:
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
232
-
233
-
234
- __all__ = ['PasswordGenerator', 'InvalidAlgorithmException']
1
+ from generator import PasswordGenerator as PasswordGenerator
2
+ from exceptions import InvalidAlgorithmException as InvalidAlgorithmException
@@ -0,0 +1,3 @@
1
+ class InvalidAlgorithmException(Exception):
2
+ def __init__(self, algorithm: str) -> None:
3
+ super().__init__(f"Invalid algorithm name {algorithm}")
@@ -0,0 +1,231 @@
1
+ from cipherspy.cipher import *
2
+
3
+ from .exceptions import InvalidAlgorithmException
4
+
5
+
6
+ class PasswordGenerator:
7
+ """
8
+ A strong password generator use multiple cipher algorithms to cipher a given plain text
9
+ """
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
+ """
20
+ :param text: plain text to be ciphered
21
+ :param shift: number of characters to shift each character (default 3)
22
+ :param multiplier: number of characters to shift each character (default 3)
23
+ :param key_str: cipher key string (default "secret")
24
+ :param key_iter: cipher key matrix (default (9, 4, 5, 7))
25
+ :param algorithm: main cipher algorithm name (default 'playfair')
26
+ """
27
+ self._chars_replacements: dict = {}
28
+ self._text: str = text
29
+ self._shift: int = shift
30
+ self._multiplier: int = multiplier
31
+ self._key_str: str = key_str
32
+ self._key_iter: iter = key_iter
33
+ self._algorithm_name: str = algorithm.lower()
34
+ self._algorithm = self._set_algorithm()
35
+ if text:
36
+ self._password: str = f"secret{self._text.replace(' ', '')}secret"
37
+ else:
38
+ self._password: str = f'secret'
39
+
40
+ @property
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
+ """
47
+ return self._text
48
+
49
+ @text.setter
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
+ """
57
+ self._text = text
58
+ self._password: str = f"secret{self._text.replace(' ', '')}secret"
59
+
60
+ @property
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
+ """
67
+ return self._shift
68
+
69
+ @shift.setter
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
+ """
77
+ self._shift = shift
78
+
79
+ @property
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
+ """
86
+ return self._multiplier
87
+
88
+ @multiplier.setter
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
+ """
96
+ self._multiplier = multiplier
97
+
98
+ @property
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
+ """
105
+ return self._key_str
106
+
107
+ @key_str.setter
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
+ """
115
+ self._key_str = key_str
116
+
117
+ @property
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
+ """
124
+ return self._key_iter
125
+
126
+ @key_iter.setter
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
+ """
134
+ self._key_iter = key_iter
135
+
136
+ @property
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
+ """
143
+ return self._algorithm_name
144
+
145
+ @algorithm.setter
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
+ """
153
+ self._algorithm_name = algorithm.lower()
154
+ self._algorithm = self._set_algorithm()
155
+
156
+ @property
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
164
+
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
+ """
170
+ match self._algorithm_name:
171
+ case 'caesar':
172
+ return CaesarCipher(self._shift)
173
+ case 'affine':
174
+ return AffineCipher(self._multiplier, self._shift)
175
+ case 'playfair':
176
+ return PlayfairCipher(self._key_str)
177
+ case 'hill':
178
+ return HillCipher(self._key_iter)
179
+ case _:
180
+ raise InvalidAlgorithmException(self._algorithm_name)
181
+
182
+ def _update_algorithm_properties(self) -> None:
183
+ """
184
+ Update the main cipher algorithm
185
+ """
186
+ self._algorithm = self._set_algorithm()
187
+
188
+ def replace_character(self, char: str, replacement: str) -> None:
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
197
+
198
+ def reset_character(self, char: str) -> None:
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]
206
+
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
+ """
212
+ self._update_algorithm_properties()
213
+ return self._algorithm.encrypt(self._password)
214
+
215
+ def generate_password(self) -> str:
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._password.replace(char, char.upper())
231
+ return self._password
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: passphera-core
3
- Version: 0.2.1
3
+ Version: 0.3.1
4
4
  Summary: The core system of passphera project
5
5
  Home-page: https://github.com/passphera/core
6
6
  Author: Fathi Abdelmalek
@@ -0,0 +1,7 @@
1
+ passphera_core/__init__.py,sha256=42-O53LSA-i4fk2xzQnhul6mhzJ7KQp8CoC6v68F8cA,139
2
+ passphera_core/exceptions.py,sha256=M0wVUORrukx2wIkHAz42Sz4BMMY8JssZp7iuHaEjARc,155
3
+ passphera_core/generator.py,sha256=pbz75NUD01ktEtGK2gCuv1B0L2z8RZHMruYukB4cg_Y,7855
4
+ passphera_core-0.3.1.dist-info/METADATA,sha256=m4wKDt2YPJSOjDhSziT9aJjypZeayyNNGyswfzKp9oM,627
5
+ passphera_core-0.3.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ passphera_core-0.3.1.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
7
+ passphera_core-0.3.1.dist-info/RECORD,,
@@ -1,5 +0,0 @@
1
- passphera_core/__init__.py,sha256=UqXK0QCs6UdD1MsysAqpHwkvUQASODzbqaPmoP9F59A,7908
2
- passphera_core-0.2.1.dist-info/METADATA,sha256=QLK_4eO9gskm0IjIQeq85FP0B82n1lTmgbVPqOdO0cA,627
3
- passphera_core-0.2.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
4
- passphera_core-0.2.1.dist-info/top_level.txt,sha256=aDUX2iWGOyfzyf6XakLWTbgeWqNrypMHO074Qratyds,15
5
- passphera_core-0.2.1.dist-info/RECORD,,