fastcrypter 2.3.9__tar.gz → 2.4.2__tar.gz
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.
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/MANIFEST.in +5 -6
- {fastcrypter-2.3.9/fastcrypter.egg-info → fastcrypter-2.4.2}/PKG-INFO +16 -47
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/README.md +6 -19
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/__init__.py +2 -2
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/custom_encoder.py +104 -85
- fastcrypter-2.4.2/fastcrypter/native/Makefile +152 -0
- fastcrypter-2.4.2/fastcrypter/native/crypto_core.c +289 -0
- fastcrypter-2.4.2/fastcrypter/native/hash_algorithms.cpp +427 -0
- fastcrypter-2.4.2/fastcrypter/native/native_loader.py +486 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2/fastcrypter.egg-info}/PKG-INFO +16 -47
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter.egg-info/SOURCES.txt +5 -1
- fastcrypter-2.4.2/fastcrypter.egg-info/entry_points.txt +2 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter.egg-info/requires.txt +0 -13
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter.egg-info/top_level.txt +0 -1
- fastcrypter-2.4.2/pyproject.toml +80 -0
- fastcrypter-2.4.2/requirements.txt +9 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/setup.py +20 -37
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_custom_encoder.py +14 -4
- fastcrypter-2.3.9/.github/workflows/pypi.yml +0 -156
- fastcrypter-2.3.9/fastcrypter.egg-info/entry_points.txt +0 -2
- fastcrypter-2.3.9/requirements.txt +0 -36
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/LICENSE +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/examples/algorithm_test.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/examples/basic_usage.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/examples/custom_encoding_test.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/examples/file_test.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/examples/native_performance_test.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/advanced_encryptor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/algorithms/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/algorithms/compression/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/algorithms/encryption/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/compressor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/encryptor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/enhanced_compressor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/core/key_manager.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/exceptions.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/file_encryptor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/secure_compressor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter/utils/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/fastcrypter.egg-info/dependency_links.txt +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/setup.cfg +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/__init__.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/conftest.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_compressor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_encryptor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_examples.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_file_encryptor.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_key_manager.py +0 -0
- {fastcrypter-2.3.9 → fastcrypter-2.4.2}/tests/test_secure_compressor.py +0 -0
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
# Include documentation files
|
|
2
2
|
include README.md
|
|
3
3
|
include LICENSE
|
|
4
|
-
include TASK.md
|
|
5
4
|
|
|
6
5
|
# Include requirements
|
|
7
6
|
include requirements.txt
|
|
8
7
|
|
|
9
8
|
# Include native library source files
|
|
10
|
-
recursive-include
|
|
11
|
-
include
|
|
9
|
+
recursive-include fastcrypter/native *.c *.cpp *.h *.hpp
|
|
10
|
+
include fastcrypter/native/Makefile
|
|
12
11
|
|
|
13
12
|
# Include compiled native libraries (if they exist)
|
|
14
|
-
recursive-include
|
|
13
|
+
recursive-include fastcrypter/native/libs *.so *.dll *.dylib
|
|
15
14
|
|
|
16
15
|
# Include examples
|
|
17
16
|
recursive-include examples *.py *.md
|
|
@@ -22,8 +21,8 @@ recursive-include tests *.py
|
|
|
22
21
|
# Include documentation
|
|
23
22
|
recursive-include docs *.md *.rst *.txt
|
|
24
23
|
|
|
25
|
-
# Include
|
|
26
|
-
|
|
24
|
+
# Include GitLab CI configuration
|
|
25
|
+
include .gitlab-ci.yml
|
|
27
26
|
|
|
28
27
|
# Exclude unnecessary files
|
|
29
28
|
global-exclude *.pyc
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastcrypter
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.2
|
|
4
4
|
Summary: Professional compression and encryption library with native C/C++ acceleration
|
|
5
|
-
Home-page: https://
|
|
5
|
+
Home-page: https://gitlab.com/Pymmdrza/fastCrypter
|
|
6
6
|
Author: Mmdrza
|
|
7
|
-
Author-email: pymmdrza@gmail.com
|
|
8
|
-
|
|
9
|
-
Project-URL:
|
|
10
|
-
Project-URL:
|
|
7
|
+
Author-email: Mmdrza <pymmdrza@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://gitlab.com/Pymmdrza/fastCrypter
|
|
10
|
+
Project-URL: Bug Reports, https://gitlab.com/Pymmdrza/fastCrypter/-/issues
|
|
11
|
+
Project-URL: Source, https://gitlab.com/Pymmdrza/fastCrypter
|
|
12
|
+
Project-URL: Documentation, https://fastcrypter.readthedocs.io/
|
|
11
13
|
Keywords: encryption,compression,security,cryptography,aes,chacha20,rsa,zlib,lzma,brotli,native,performance,c++,custom-encoding,fast
|
|
12
14
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
15
|
Classifier: Intended Audience :: Developers
|
|
@@ -19,6 +21,8 @@ Classifier: Programming Language :: Python :: 3.9
|
|
|
19
21
|
Classifier: Programming Language :: Python :: 3.10
|
|
20
22
|
Classifier: Programming Language :: Python :: 3.11
|
|
21
23
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
26
|
Classifier: Topic :: Security :: Cryptography
|
|
23
27
|
Classifier: Topic :: System :: Archiving :: Compression
|
|
24
28
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
@@ -29,19 +33,6 @@ Requires-Dist: cryptography
|
|
|
29
33
|
Requires-Dist: pycryptodome
|
|
30
34
|
Requires-Dist: brotli
|
|
31
35
|
Requires-Dist: argon2-cffi
|
|
32
|
-
Requires-Dist: bcrypt
|
|
33
|
-
Requires-Dist: numpy
|
|
34
|
-
Requires-Dist: cython
|
|
35
|
-
Requires-Dist: pytest
|
|
36
|
-
Requires-Dist: pytest-cov
|
|
37
|
-
Requires-Dist: pytest-benchmark
|
|
38
|
-
Requires-Dist: black
|
|
39
|
-
Requires-Dist: flake8
|
|
40
|
-
Requires-Dist: mypy
|
|
41
|
-
Requires-Dist: sphinx
|
|
42
|
-
Requires-Dist: sphinx-rtd-theme
|
|
43
|
-
Requires-Dist: psutil
|
|
44
|
-
Requires-Dist: tqdm
|
|
45
36
|
Provides-Extra: dev
|
|
46
37
|
Requires-Dist: pytest>=7.4.0; extra == "dev"
|
|
47
38
|
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
|
|
@@ -56,23 +47,15 @@ Provides-Extra: native
|
|
|
56
47
|
Requires-Dist: numpy>=1.24.0; extra == "native"
|
|
57
48
|
Requires-Dist: cython>=3.0.0; extra == "native"
|
|
58
49
|
Dynamic: author
|
|
59
|
-
Dynamic: author-email
|
|
60
|
-
Dynamic: classifier
|
|
61
|
-
Dynamic: description
|
|
62
|
-
Dynamic: description-content-type
|
|
63
50
|
Dynamic: home-page
|
|
64
|
-
Dynamic: keywords
|
|
65
51
|
Dynamic: license-file
|
|
66
|
-
Dynamic: project-url
|
|
67
|
-
Dynamic: provides-extra
|
|
68
|
-
Dynamic: requires-dist
|
|
69
52
|
Dynamic: requires-python
|
|
70
|
-
Dynamic: summary
|
|
71
53
|
|
|
72
54
|
# fastCrypter
|
|
73
55
|
|
|
74
56
|
**Professional Compression and Encryption Library with Native C/C++ Acceleration**
|
|
75
57
|
|
|
58
|
+
[](https://gitlab.com/Pymmdrza/fastCrypter/-/pipelines)
|
|
76
59
|
[](https://python.org)
|
|
77
60
|
[](LICENSE)
|
|
78
61
|
[](https://pypi.org/project/fastcrypter/)
|
|
@@ -292,7 +275,7 @@ python final_test.py
|
|
|
292
275
|
|
|
293
276
|
```bash
|
|
294
277
|
# Clone repository
|
|
295
|
-
git clone https://
|
|
278
|
+
git clone https://gitlab.com/Pymmdrza/fastCrypter.git
|
|
296
279
|
cd fastCrypter
|
|
297
280
|
|
|
298
281
|
# Install in development mode
|
|
@@ -320,22 +303,8 @@ mypy fastcrypter/
|
|
|
320
303
|
|
|
321
304
|
## Documentation
|
|
322
305
|
|
|
323
|
-
- **API Reference**: [ [Document](
|
|
324
|
-
- **Examples**: See `examples/` directory [Examples](https://
|
|
325
|
-
- **Performance Guide**: [Performance Optimization](docs/performance.md)
|
|
326
|
-
|
|
327
|
-
## Contributing
|
|
328
|
-
|
|
329
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
330
|
-
|
|
331
|
-
### Development Workflow
|
|
332
|
-
|
|
333
|
-
1. Fork the repository
|
|
334
|
-
2. Create a feature branch
|
|
335
|
-
3. Make your changes
|
|
336
|
-
4. Add tests for new functionality
|
|
337
|
-
5. Ensure all tests pass
|
|
338
|
-
6. Submit a pull request
|
|
306
|
+
- **API Reference**: [ [Document](misc/API_REFERENCE.md) ]
|
|
307
|
+
- **Examples**: See `examples/` directory [Examples](https://gitlab.com/Pymmdrza/fastCrypter/-/tree/main/examples)
|
|
339
308
|
|
|
340
309
|
## License
|
|
341
310
|
|
|
@@ -350,8 +319,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
350
319
|
|
|
351
320
|
## Support
|
|
352
321
|
|
|
353
|
-
- **Issues**: [
|
|
354
|
-
- **Discussions**: [
|
|
322
|
+
- **Issues**: [GitLab Issues](https://gitlab.com/Pymmdrza/fastCrypter/-/issues)
|
|
323
|
+
- **Discussions**: [GitLab Discussions](https://gitlab.com/Pymmdrza/fastCrypter/-/discussions)
|
|
355
324
|
- **Email**: pymmdrza@gmail.com
|
|
356
325
|
|
|
357
326
|
---
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**Professional Compression and Encryption Library with Native C/C++ Acceleration**
|
|
4
4
|
|
|
5
|
+
[](https://gitlab.com/Pymmdrza/fastCrypter/-/pipelines)
|
|
5
6
|
[](https://python.org)
|
|
6
7
|
[](LICENSE)
|
|
7
8
|
[](https://pypi.org/project/fastcrypter/)
|
|
@@ -221,7 +222,7 @@ python final_test.py
|
|
|
221
222
|
|
|
222
223
|
```bash
|
|
223
224
|
# Clone repository
|
|
224
|
-
git clone https://
|
|
225
|
+
git clone https://gitlab.com/Pymmdrza/fastCrypter.git
|
|
225
226
|
cd fastCrypter
|
|
226
227
|
|
|
227
228
|
# Install in development mode
|
|
@@ -249,22 +250,8 @@ mypy fastcrypter/
|
|
|
249
250
|
|
|
250
251
|
## Documentation
|
|
251
252
|
|
|
252
|
-
- **API Reference**: [ [Document](
|
|
253
|
-
- **Examples**: See `examples/` directory [Examples](https://
|
|
254
|
-
- **Performance Guide**: [Performance Optimization](docs/performance.md)
|
|
255
|
-
|
|
256
|
-
## Contributing
|
|
257
|
-
|
|
258
|
-
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
|
|
259
|
-
|
|
260
|
-
### Development Workflow
|
|
261
|
-
|
|
262
|
-
1. Fork the repository
|
|
263
|
-
2. Create a feature branch
|
|
264
|
-
3. Make your changes
|
|
265
|
-
4. Add tests for new functionality
|
|
266
|
-
5. Ensure all tests pass
|
|
267
|
-
6. Submit a pull request
|
|
253
|
+
- **API Reference**: [ [Document](misc/API_REFERENCE.md) ]
|
|
254
|
+
- **Examples**: See `examples/` directory [Examples](https://gitlab.com/Pymmdrza/fastCrypter/-/tree/main/examples)
|
|
268
255
|
|
|
269
256
|
## License
|
|
270
257
|
|
|
@@ -279,8 +266,8 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
|
279
266
|
|
|
280
267
|
## Support
|
|
281
268
|
|
|
282
|
-
- **Issues**: [
|
|
283
|
-
- **Discussions**: [
|
|
269
|
+
- **Issues**: [GitLab Issues](https://gitlab.com/Pymmdrza/fastCrypter/-/issues)
|
|
270
|
+
- **Discussions**: [GitLab Discussions](https://gitlab.com/Pymmdrza/fastCrypter/-/discussions)
|
|
284
271
|
- **Email**: pymmdrza@gmail.com
|
|
285
272
|
|
|
286
273
|
---
|
|
@@ -10,7 +10,7 @@ Version: 2.0.0
|
|
|
10
10
|
License: MIT
|
|
11
11
|
"""
|
|
12
12
|
|
|
13
|
-
__version__ = "2.
|
|
13
|
+
__version__ = "2.4.0"
|
|
14
14
|
__author__ = "Mmdrza"
|
|
15
15
|
__email__ = "pymmdrza@gmail.com"
|
|
16
16
|
__license__ = "MIT"
|
|
@@ -111,7 +111,7 @@ PACKAGE_INFO = {
|
|
|
111
111
|
"author": __author__,
|
|
112
112
|
"email": __email__,
|
|
113
113
|
"license": __license__,
|
|
114
|
-
"url": "https://
|
|
114
|
+
"url": "https://gitlab.com/Pymmdrza/fastCrypter",
|
|
115
115
|
"keywords": [
|
|
116
116
|
"encryption", "compression", "security", "cryptography",
|
|
117
117
|
"aes", "chacha20", "rsa", "zlib", "lzma", "brotli",
|
|
@@ -32,9 +32,9 @@ class CustomEncoder:
|
|
|
32
32
|
Raises:
|
|
33
33
|
ValidationError: If charset is invalid.
|
|
34
34
|
"""
|
|
35
|
-
if not charset or len(charset) <
|
|
35
|
+
if not charset or len(charset) < 8:
|
|
36
36
|
raise ValidationError(
|
|
37
|
-
"Charset must contain at least
|
|
37
|
+
f"Charset must contain at least 8 characters, got {len(charset) if charset else 0}",
|
|
38
38
|
ErrorCodes.INVALID_CONFIGURATION
|
|
39
39
|
)
|
|
40
40
|
|
|
@@ -42,9 +42,9 @@ class CustomEncoder:
|
|
|
42
42
|
seen = set()
|
|
43
43
|
self.charset = ''.join(char for char in charset if not (char in seen or seen.add(char)))
|
|
44
44
|
|
|
45
|
-
if len(self.charset) <
|
|
45
|
+
if len(self.charset) < 8:
|
|
46
46
|
raise ValidationError(
|
|
47
|
-
"Charset must contain at least
|
|
47
|
+
f"Charset must contain at least 8 unique characters, got {len(self.charset)}",
|
|
48
48
|
ErrorCodes.INVALID_CONFIGURATION
|
|
49
49
|
)
|
|
50
50
|
|
|
@@ -55,16 +55,34 @@ class CustomEncoder:
|
|
|
55
55
|
self.char_to_value = {char: i for i, char in enumerate(self.charset)}
|
|
56
56
|
self.value_to_char = {i: char for i, char in enumerate(self.charset)}
|
|
57
57
|
|
|
58
|
+
# Maximum chunk size in bytes for chunked encoding (keeps big-int ops fast)
|
|
59
|
+
_CHUNK_SIZE = 6
|
|
60
|
+
|
|
61
|
+
# Fixed number of characters for the length prefix field.
|
|
62
|
+
# With base >= 8 this supports up to 8^6 = 262144 bytes which is plenty.
|
|
63
|
+
# We use 6 as a safe default for all bases >= 8.
|
|
64
|
+
_LENGTH_PREFIX_CHARS = 6
|
|
65
|
+
|
|
66
|
+
def _chars_per_chunk(self) -> int:
|
|
67
|
+
"""Number of encoded characters per chunk (fixed-width padding target)."""
|
|
68
|
+
import math
|
|
69
|
+
return math.ceil(self._CHUNK_SIZE * 8 / math.log2(self.base))
|
|
70
|
+
|
|
58
71
|
def encode(self, data: Union[bytes, bytearray]) -> str:
|
|
59
72
|
"""
|
|
60
73
|
Encode binary data to custom character set.
|
|
61
|
-
|
|
74
|
+
|
|
75
|
+
Uses chunked encoding for O(n) performance on large data instead of
|
|
76
|
+
the naive single-big-int approach which is O(n^2).
|
|
77
|
+
|
|
78
|
+
Format: [fixed-width length prefix][chunk1][chunk2]...
|
|
79
|
+
|
|
62
80
|
Args:
|
|
63
81
|
data: Binary data to encode.
|
|
64
|
-
|
|
82
|
+
|
|
65
83
|
Returns:
|
|
66
84
|
str: Encoded string using custom charset.
|
|
67
|
-
|
|
85
|
+
|
|
68
86
|
Raises:
|
|
69
87
|
ValidationError: If data is invalid.
|
|
70
88
|
"""
|
|
@@ -73,40 +91,48 @@ class CustomEncoder:
|
|
|
73
91
|
"Data must be bytes or bytearray",
|
|
74
92
|
ErrorCodes.INVALID_INPUT_FORMAT
|
|
75
93
|
)
|
|
76
|
-
|
|
94
|
+
|
|
77
95
|
if len(data) == 0:
|
|
78
96
|
return ""
|
|
79
|
-
|
|
80
|
-
#
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if number == 0:
|
|
84
|
-
return self.charset[0]
|
|
85
|
-
|
|
86
|
-
# Convert to custom base
|
|
87
|
-
result = []
|
|
88
|
-
while number > 0:
|
|
89
|
-
result.append(self.value_to_char[number % self.base])
|
|
90
|
-
number //= self.base
|
|
91
|
-
|
|
92
|
-
# Reverse to get correct order
|
|
93
|
-
encoded = ''.join(reversed(result))
|
|
94
|
-
|
|
95
|
-
# Add length prefix to handle leading zeros
|
|
97
|
+
|
|
98
|
+
# Fixed-width length prefix: encode len(data) in base-N, left-padded
|
|
99
|
+
# to _LENGTH_PREFIX_CHARS characters. No separator character needed.
|
|
96
100
|
length_prefix = self._encode_length(len(data))
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
|
|
102
|
+
# Encode data in fixed-size chunks to avoid giant big-int operations.
|
|
103
|
+
chunk_size = self._CHUNK_SIZE
|
|
104
|
+
chars_per = self._chars_per_chunk()
|
|
105
|
+
pad_char = self.charset[0]
|
|
106
|
+
encoded_parts = []
|
|
107
|
+
|
|
108
|
+
for offset in range(0, len(data), chunk_size):
|
|
109
|
+
chunk = data[offset:offset + chunk_size]
|
|
110
|
+
number = int.from_bytes(chunk, byteorder='big')
|
|
111
|
+
chars = []
|
|
112
|
+
if number == 0:
|
|
113
|
+
chars = [pad_char] * chars_per
|
|
114
|
+
else:
|
|
115
|
+
while number > 0:
|
|
116
|
+
chars.append(self.value_to_char[number % self.base])
|
|
117
|
+
number //= self.base
|
|
118
|
+
# Left-pad to fixed width
|
|
119
|
+
while len(chars) < chars_per:
|
|
120
|
+
chars.append(pad_char)
|
|
121
|
+
chars.reverse()
|
|
122
|
+
encoded_parts.append(''.join(chars))
|
|
123
|
+
|
|
124
|
+
return length_prefix + ''.join(encoded_parts)
|
|
125
|
+
|
|
100
126
|
def decode(self, encoded: str) -> bytes:
|
|
101
127
|
"""
|
|
102
128
|
Decode custom encoded string back to binary data.
|
|
103
|
-
|
|
129
|
+
|
|
104
130
|
Args:
|
|
105
131
|
encoded: Encoded string to decode.
|
|
106
|
-
|
|
132
|
+
|
|
107
133
|
Returns:
|
|
108
134
|
bytes: Original binary data.
|
|
109
|
-
|
|
135
|
+
|
|
110
136
|
Raises:
|
|
111
137
|
ValidationError: If encoded string is invalid.
|
|
112
138
|
"""
|
|
@@ -115,10 +141,10 @@ class CustomEncoder:
|
|
|
115
141
|
"Encoded data must be string",
|
|
116
142
|
ErrorCodes.INVALID_INPUT_FORMAT
|
|
117
143
|
)
|
|
118
|
-
|
|
144
|
+
|
|
119
145
|
if len(encoded) == 0:
|
|
120
146
|
return b""
|
|
121
|
-
|
|
147
|
+
|
|
122
148
|
# Validate characters
|
|
123
149
|
for char in encoded:
|
|
124
150
|
if char not in self.char_to_value:
|
|
@@ -126,65 +152,58 @@ class CustomEncoder:
|
|
|
126
152
|
f"Invalid character '{char}' in encoded data",
|
|
127
153
|
ErrorCodes.INVALID_INPUT_FORMAT
|
|
128
154
|
)
|
|
129
|
-
|
|
130
|
-
# Extract length prefix
|
|
155
|
+
|
|
156
|
+
# Extract length from fixed-width prefix
|
|
131
157
|
original_length, data_start = self._decode_length(encoded)
|
|
132
158
|
encoded_data = encoded[data_start:]
|
|
133
|
-
|
|
159
|
+
|
|
134
160
|
if len(encoded_data) == 0:
|
|
135
161
|
return b'\x00' * original_length
|
|
136
|
-
|
|
137
|
-
#
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
162
|
+
|
|
163
|
+
# Split into fixed-width chunks and decode each, tracking expected
|
|
164
|
+
# byte count per chunk so leading zeros within a chunk are preserved.
|
|
165
|
+
chars_per = self._chars_per_chunk()
|
|
166
|
+
chunk_size = self._CHUNK_SIZE
|
|
167
|
+
decoded_parts = []
|
|
168
|
+
bytes_remaining = original_length
|
|
169
|
+
|
|
170
|
+
for offset in range(0, len(encoded_data), chars_per):
|
|
171
|
+
chunk = encoded_data[offset:offset + chars_per]
|
|
172
|
+
number = 0
|
|
173
|
+
for char in chunk:
|
|
174
|
+
number = number * self.base + self.char_to_value[char]
|
|
175
|
+
|
|
176
|
+
# This chunk represents min(chunk_size, bytes_remaining) bytes
|
|
177
|
+
expected = min(chunk_size, bytes_remaining)
|
|
178
|
+
if number == 0:
|
|
179
|
+
decoded_parts.append(b'\x00' * expected)
|
|
180
|
+
else:
|
|
181
|
+
byte_length = (number.bit_length() + 7) // 8
|
|
182
|
+
raw = number.to_bytes(byte_length, byteorder='big')
|
|
183
|
+
# Left-pad with zeros to the expected size
|
|
184
|
+
if len(raw) < expected:
|
|
185
|
+
raw = b'\x00' * (expected - len(raw)) + raw
|
|
186
|
+
decoded_parts.append(raw)
|
|
187
|
+
bytes_remaining -= expected
|
|
188
|
+
|
|
189
|
+
return b''.join(decoded_parts)
|
|
190
|
+
|
|
156
191
|
def _encode_length(self, length: int) -> str:
|
|
157
|
-
"""Encode length as prefix using custom charset."""
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
# Add separator
|
|
167
|
-
return ''.join(reversed(result)) + self.padding_char
|
|
168
|
-
|
|
192
|
+
"""Encode length as a fixed-width prefix using custom charset."""
|
|
193
|
+
chars = []
|
|
194
|
+
n = length
|
|
195
|
+
for _ in range(self._LENGTH_PREFIX_CHARS):
|
|
196
|
+
chars.append(self.value_to_char[n % self.base])
|
|
197
|
+
n //= self.base
|
|
198
|
+
chars.reverse()
|
|
199
|
+
return ''.join(chars)
|
|
200
|
+
|
|
169
201
|
def _decode_length(self, encoded: str) -> Tuple[int, int]:
|
|
170
|
-
"""Decode length prefix and return (length, data_start_index)."""
|
|
171
|
-
separator_pos = encoded.find(self.padding_char)
|
|
172
|
-
if separator_pos == -1:
|
|
173
|
-
raise ValidationError(
|
|
174
|
-
"Invalid encoded format: missing length separator",
|
|
175
|
-
ErrorCodes.INVALID_INPUT_FORMAT
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
length_part = encoded[:separator_pos]
|
|
179
|
-
if len(length_part) == 0:
|
|
180
|
-
return 0, separator_pos + 1
|
|
181
|
-
|
|
182
|
-
# Decode length
|
|
202
|
+
"""Decode fixed-width length prefix and return (length, data_start_index)."""
|
|
183
203
|
length = 0
|
|
184
|
-
for
|
|
185
|
-
length = length * self.base + self.char_to_value[
|
|
186
|
-
|
|
187
|
-
return length, separator_pos + 1
|
|
204
|
+
for i in range(self._LENGTH_PREFIX_CHARS):
|
|
205
|
+
length = length * self.base + self.char_to_value[encoded[i]]
|
|
206
|
+
return length, self._LENGTH_PREFIX_CHARS
|
|
188
207
|
|
|
189
208
|
def encode_with_noise(self, data: Union[bytes, bytearray], noise_ratio: float = 0.1) -> str:
|
|
190
209
|
"""
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Makefile for Encrypter Native Libraries
|
|
2
|
+
# Compiles C/C++ code to shared libraries (.so/.dll)
|
|
3
|
+
|
|
4
|
+
# Compiler settings
|
|
5
|
+
CC = gcc
|
|
6
|
+
CXX = g++
|
|
7
|
+
CFLAGS = -O3 -fPIC -Wall -Wextra -march=native -ffast-math
|
|
8
|
+
CXXFLAGS = -O3 -fPIC -Wall -Wextra -march=native -ffast-math -std=c++17
|
|
9
|
+
LDFLAGS = -shared
|
|
10
|
+
|
|
11
|
+
# Platform detection
|
|
12
|
+
UNAME_S := $(shell uname -s)
|
|
13
|
+
ifeq ($(UNAME_S),Linux)
|
|
14
|
+
PLATFORM = linux
|
|
15
|
+
LIB_EXT = .so
|
|
16
|
+
CFLAGS += -DLINUX
|
|
17
|
+
CXXFLAGS += -DLINUX
|
|
18
|
+
LDFLAGS += -lm
|
|
19
|
+
endif
|
|
20
|
+
ifeq ($(UNAME_S),Darwin)
|
|
21
|
+
PLATFORM = macos
|
|
22
|
+
LIB_EXT = .dylib
|
|
23
|
+
CFLAGS += -DMACOS
|
|
24
|
+
CXXFLAGS += -DMACOS
|
|
25
|
+
LDFLAGS += -lm
|
|
26
|
+
endif
|
|
27
|
+
ifeq ($(OS),Windows_NT)
|
|
28
|
+
PLATFORM = windows
|
|
29
|
+
LIB_EXT = .dll
|
|
30
|
+
CC = x86_64-w64-mingw32-gcc
|
|
31
|
+
CXX = x86_64-w64-mingw32-g++
|
|
32
|
+
CFLAGS += -DWINDOWS
|
|
33
|
+
CXXFLAGS += -DWINDOWS
|
|
34
|
+
LDFLAGS += -Wl,--out-implib,lib$@.a
|
|
35
|
+
endif
|
|
36
|
+
|
|
37
|
+
# Output directory
|
|
38
|
+
OUTDIR = ../libs/$(PLATFORM)
|
|
39
|
+
|
|
40
|
+
# Source files
|
|
41
|
+
CRYPTO_CORE_SRC = crypto_core.c
|
|
42
|
+
HASH_ALGORITHMS_SRC = hash_algorithms.cpp
|
|
43
|
+
|
|
44
|
+
# Output libraries
|
|
45
|
+
CRYPTO_CORE_LIB = $(OUTDIR)/libcrypto_core$(LIB_EXT)
|
|
46
|
+
HASH_ALGORITHMS_LIB = $(OUTDIR)/libhash_algorithms$(LIB_EXT)
|
|
47
|
+
|
|
48
|
+
# Default target
|
|
49
|
+
all: setup $(CRYPTO_CORE_LIB) $(HASH_ALGORITHMS_LIB)
|
|
50
|
+
|
|
51
|
+
# Create output directory
|
|
52
|
+
setup:
|
|
53
|
+
@mkdir -p $(OUTDIR)
|
|
54
|
+
@echo "Building for platform: $(PLATFORM)"
|
|
55
|
+
@echo "Library extension: $(LIB_EXT)"
|
|
56
|
+
|
|
57
|
+
# Compile crypto_core library
|
|
58
|
+
$(CRYPTO_CORE_LIB): $(CRYPTO_CORE_SRC)
|
|
59
|
+
@echo "Compiling crypto_core library..."
|
|
60
|
+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
|
|
61
|
+
@echo "✅ crypto_core library built: $@"
|
|
62
|
+
|
|
63
|
+
# Compile hash_algorithms library
|
|
64
|
+
$(HASH_ALGORITHMS_LIB): $(HASH_ALGORITHMS_SRC)
|
|
65
|
+
@echo "Compiling hash_algorithms library..."
|
|
66
|
+
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $<
|
|
67
|
+
@echo "✅ hash_algorithms library built: $@"
|
|
68
|
+
|
|
69
|
+
# Clean build artifacts
|
|
70
|
+
clean:
|
|
71
|
+
@echo "Cleaning build artifacts..."
|
|
72
|
+
rm -rf ../libs/
|
|
73
|
+
@echo "✅ Clean completed"
|
|
74
|
+
|
|
75
|
+
# Install libraries to system (optional)
|
|
76
|
+
install: all
|
|
77
|
+
@echo "Installing libraries to system..."
|
|
78
|
+
ifeq ($(PLATFORM),linux)
|
|
79
|
+
sudo cp $(CRYPTO_CORE_LIB) /usr/local/lib/
|
|
80
|
+
sudo cp $(HASH_ALGORITHMS_LIB) /usr/local/lib/
|
|
81
|
+
sudo ldconfig
|
|
82
|
+
endif
|
|
83
|
+
ifeq ($(PLATFORM),macos)
|
|
84
|
+
sudo cp $(CRYPTO_CORE_LIB) /usr/local/lib/
|
|
85
|
+
sudo cp $(HASH_ALGORITHMS_LIB) /usr/local/lib/
|
|
86
|
+
endif
|
|
87
|
+
@echo "✅ Libraries installed"
|
|
88
|
+
|
|
89
|
+
# Test libraries
|
|
90
|
+
test: all
|
|
91
|
+
@echo "Testing libraries..."
|
|
92
|
+
@echo "Checking if libraries can be loaded..."
|
|
93
|
+
ifeq ($(PLATFORM),linux)
|
|
94
|
+
ldd $(CRYPTO_CORE_LIB)
|
|
95
|
+
ldd $(HASH_ALGORITHMS_LIB)
|
|
96
|
+
endif
|
|
97
|
+
ifeq ($(PLATFORM),macos)
|
|
98
|
+
otool -L $(CRYPTO_CORE_LIB)
|
|
99
|
+
otool -L $(HASH_ALGORITHMS_LIB)
|
|
100
|
+
endif
|
|
101
|
+
@echo "✅ Library test completed"
|
|
102
|
+
|
|
103
|
+
# Debug build
|
|
104
|
+
debug: CFLAGS += -g -DDEBUG -O0
|
|
105
|
+
debug: CXXFLAGS += -g -DDEBUG -O0
|
|
106
|
+
debug: all
|
|
107
|
+
|
|
108
|
+
# Release build with maximum optimization
|
|
109
|
+
release: CFLAGS += -DNDEBUG -flto -funroll-loops
|
|
110
|
+
release: CXXFLAGS += -DNDEBUG -flto -funroll-loops
|
|
111
|
+
release: LDFLAGS += -flto
|
|
112
|
+
release: all
|
|
113
|
+
|
|
114
|
+
# Cross-compile for Windows (from Linux)
|
|
115
|
+
windows:
|
|
116
|
+
@echo "Cross-compiling for Windows..."
|
|
117
|
+
$(MAKE) OS=Windows_NT
|
|
118
|
+
|
|
119
|
+
# Show build information
|
|
120
|
+
info:
|
|
121
|
+
@echo "Build Information:"
|
|
122
|
+
@echo " Platform: $(PLATFORM)"
|
|
123
|
+
@echo " C Compiler: $(CC)"
|
|
124
|
+
@echo " C++ Compiler: $(CXX)"
|
|
125
|
+
@echo " C Flags: $(CFLAGS)"
|
|
126
|
+
@echo " C++ Flags: $(CXXFLAGS)"
|
|
127
|
+
@echo " LD Flags: $(LDFLAGS)"
|
|
128
|
+
@echo " Library Extension: $(LIB_EXT)"
|
|
129
|
+
@echo " Output Directory: $(OUTDIR)"
|
|
130
|
+
|
|
131
|
+
# Help
|
|
132
|
+
help:
|
|
133
|
+
@echo "Encrypter Native Libraries Build System"
|
|
134
|
+
@echo ""
|
|
135
|
+
@echo "Targets:"
|
|
136
|
+
@echo " all - Build all libraries (default)"
|
|
137
|
+
@echo " clean - Clean build artifacts"
|
|
138
|
+
@echo " install - Install libraries to system"
|
|
139
|
+
@echo " test - Test built libraries"
|
|
140
|
+
@echo " debug - Build with debug symbols"
|
|
141
|
+
@echo " release - Build with maximum optimization"
|
|
142
|
+
@echo " windows - Cross-compile for Windows"
|
|
143
|
+
@echo " info - Show build information"
|
|
144
|
+
@echo " help - Show this help"
|
|
145
|
+
@echo ""
|
|
146
|
+
@echo "Examples:"
|
|
147
|
+
@echo " make # Build all libraries"
|
|
148
|
+
@echo " make clean all # Clean and rebuild"
|
|
149
|
+
@echo " make release # Optimized build"
|
|
150
|
+
@echo " make debug test # Debug build and test"
|
|
151
|
+
|
|
152
|
+
.PHONY: all setup clean install test debug release windows info help
|