advanced-encoder-and-decoder 1.0.0__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.
- advanced_encoder_and_decoder-1.0.0/LICENSE.txt +8 -0
- advanced_encoder_and_decoder-1.0.0/PKG-INFO +21 -0
- advanced_encoder_and_decoder-1.0.0/README.md +7 -0
- advanced_encoder_and_decoder-1.0.0/pyproject.toml +23 -0
- advanced_encoder_and_decoder-1.0.0/setup.cfg +4 -0
- advanced_encoder_and_decoder-1.0.0/src/__init__.py +3 -0
- advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.egg-info/PKG-INFO +21 -0
- advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.egg-info/SOURCES.txt +9 -0
- advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.egg-info/dependency_links.txt +1 -0
- advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.egg-info/top_level.txt +2 -0
- advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.py +130 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
Copyright 2026 Andrew Abdelmalek
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: advanced_encoder_and_decoder
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A small, easy to use module that helps you store data easily.
|
|
5
|
+
Author-email: Andrew Abdelmalek <aa2@olprahraneast.catholic.edu.au>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://simple-storage-module.netlify.app
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# advanced_encoder_and_decoder
|
|
16
|
+
|
|
17
|
+
A complex encryption/decryption module
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
```bash
|
|
21
|
+
pip install advanced_encoder_and_decoder
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "advanced_encoder_and_decoder"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Andrew Abdelmalek", email="aa2@olprahraneast.catholic.edu.au" },
|
|
10
|
+
]
|
|
11
|
+
description = "A small, easy to use module that helps you store data easily."
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.9"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: OS Independent",
|
|
17
|
+
]
|
|
18
|
+
license = "MIT"
|
|
19
|
+
license-files = ["LICENSE.txt"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://simple-storage-module.netlify.app"
|
|
23
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: advanced_encoder_and_decoder
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A small, easy to use module that helps you store data easily.
|
|
5
|
+
Author-email: Andrew Abdelmalek <aa2@olprahraneast.catholic.edu.au>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://simple-storage-module.netlify.app
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.txt
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# advanced_encoder_and_decoder
|
|
16
|
+
|
|
17
|
+
A complex encryption/decryption module
|
|
18
|
+
|
|
19
|
+
## Install
|
|
20
|
+
```bash
|
|
21
|
+
pip install advanced_encoder_and_decoder
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/__init__.py
|
|
5
|
+
src/advanced_encoder_and_decoder.py
|
|
6
|
+
src/advanced_encoder_and_decoder.egg-info/PKG-INFO
|
|
7
|
+
src/advanced_encoder_and_decoder.egg-info/SOURCES.txt
|
|
8
|
+
src/advanced_encoder_and_decoder.egg-info/dependency_links.txt
|
|
9
|
+
src/advanced_encoder_and_decoder.egg-info/top_level.txt
|
advanced_encoder_and_decoder-1.0.0/src/advanced_encoder_and_decoder.egg-info/dependency_links.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import os
|
|
3
|
+
import zlib
|
|
4
|
+
import random
|
|
5
|
+
import string
|
|
6
|
+
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
|
7
|
+
from cryptography.hazmat.primitives import hashes
|
|
8
|
+
from cryptography.fernet import Fernet
|
|
9
|
+
from cryptography.hazmat.backends import default_backend
|
|
10
|
+
|
|
11
|
+
# ===================== CONFIG =====================
|
|
12
|
+
ITERATIONS = 200_000
|
|
13
|
+
CUSTOM_PASSES = 3
|
|
14
|
+
CHUNK_SIZE = 5000
|
|
15
|
+
|
|
16
|
+
# ===================== PASSWORD GENERATOR =====================
|
|
17
|
+
def generate_password(length: int = 24) -> str:
|
|
18
|
+
"""Generates a high-entropy secure password."""
|
|
19
|
+
chars = string.ascii_letters + string.digits + string.punctuation
|
|
20
|
+
return ''.join(random.SystemRandom().choice(chars) for _ in range(length))
|
|
21
|
+
|
|
22
|
+
# ===================== CORE CRYPTO FUNCTIONS =====================
|
|
23
|
+
def _derive_key(password: str, salt: bytes) -> bytes:
|
|
24
|
+
kdf = PBKDF2HMAC(
|
|
25
|
+
algorithm=hashes.SHA256(),
|
|
26
|
+
length=32,
|
|
27
|
+
salt=salt,
|
|
28
|
+
iterations=ITERATIONS,
|
|
29
|
+
backend=default_backend()
|
|
30
|
+
)
|
|
31
|
+
return base64.urlsafe_b64encode(kdf.derive(password.encode()))
|
|
32
|
+
|
|
33
|
+
def _aes_encrypt(data: bytes, password: str) -> bytes:
|
|
34
|
+
salt = os.urandom(16)
|
|
35
|
+
key = _derive_key(password, salt)
|
|
36
|
+
return salt + Fernet(key).encrypt(data)
|
|
37
|
+
|
|
38
|
+
def _aes_decrypt(data: bytes, password: str) -> bytes:
|
|
39
|
+
salt, encrypted = data[:16], data[16:]
|
|
40
|
+
key = _derive_key(password, salt)
|
|
41
|
+
return Fernet(key).decrypt(encrypted)
|
|
42
|
+
|
|
43
|
+
def _custom_encode(data: bytes, password: str, r: int) -> bytes:
|
|
44
|
+
shift = (sum(password.encode()) + r) % 256
|
|
45
|
+
return bytes((b + shift) % 256 for b in data)
|
|
46
|
+
|
|
47
|
+
def _custom_decode(data: bytes, password: str, r: int) -> bytes:
|
|
48
|
+
shift = (sum(password.encode()) + r) % 256
|
|
49
|
+
return bytes((b - shift) % 256 for b in data)
|
|
50
|
+
|
|
51
|
+
def _rotate_bits(data: bytes, password: str, rev=False) -> bytes:
|
|
52
|
+
r = len(password) % 8
|
|
53
|
+
if r == 0: return data
|
|
54
|
+
out = bytearray()
|
|
55
|
+
for b in data:
|
|
56
|
+
out.append(((b >> r | b << (8 - r)) if rev else (b << r | b >> (8 - r))) & 0xFF)
|
|
57
|
+
return bytes(out)
|
|
58
|
+
|
|
59
|
+
def _substitution_table(password: str) -> bytes:
|
|
60
|
+
seed = sum(password.encode())
|
|
61
|
+
table = list(range(256))
|
|
62
|
+
for i in range(256):
|
|
63
|
+
j = (i + seed) % 256
|
|
64
|
+
table[i], table[j] = table[j], table[i]
|
|
65
|
+
return bytes(table)
|
|
66
|
+
|
|
67
|
+
def _substitute(data: bytes, table: bytes, rev=False) -> bytes:
|
|
68
|
+
if not rev: return bytes(table[b] for b in data)
|
|
69
|
+
inv = bytearray(256)
|
|
70
|
+
for i, v in enumerate(table): inv[v] = i
|
|
71
|
+
return bytes(inv[b] for b in data)
|
|
72
|
+
|
|
73
|
+
# ===================== MAIN WRAPPERS =====================
|
|
74
|
+
def _encrypt_text(raw_text: str, password: str) -> str:
|
|
75
|
+
chunks = [raw_text[i:i+CHUNK_SIZE] for i in range(0, len(raw_text), CHUNK_SIZE)]
|
|
76
|
+
encrypted_chunks = []
|
|
77
|
+
table = _substitution_table(password)
|
|
78
|
+
|
|
79
|
+
for chunk in chunks:
|
|
80
|
+
data = chunk.encode()
|
|
81
|
+
for i in range(CUSTOM_PASSES):
|
|
82
|
+
data = _custom_encode(data, password, i)
|
|
83
|
+
data = _rotate_bits(data, password)
|
|
84
|
+
data = zlib.compress(data)
|
|
85
|
+
data = _aes_encrypt(data, password)
|
|
86
|
+
data = _substitute(data, table)
|
|
87
|
+
encrypted_chunks.append(base64.b64encode(data).decode())
|
|
88
|
+
|
|
89
|
+
return "\n".join(encrypted_chunks)
|
|
90
|
+
|
|
91
|
+
def _decrypt_text(encrypted_text: str, password: str) -> str:
|
|
92
|
+
chunks = encrypted_text.strip().split("\n")
|
|
93
|
+
decrypted_chunks = []
|
|
94
|
+
table = _substitution_table(password)
|
|
95
|
+
|
|
96
|
+
for chunk in chunks:
|
|
97
|
+
data = base64.b64decode(chunk)
|
|
98
|
+
data = _substitute(data, table, True)
|
|
99
|
+
data = _aes_decrypt(data, password)
|
|
100
|
+
data = zlib.decompress(data)
|
|
101
|
+
data = _rotate_bits(data, password, True)
|
|
102
|
+
for i in reversed(range(CUSTOM_PASSES)):
|
|
103
|
+
data = _custom_decode(data, password, i)
|
|
104
|
+
decrypted_chunks.append(data.decode())
|
|
105
|
+
|
|
106
|
+
return "".join(decrypted_chunks)
|
|
107
|
+
|
|
108
|
+
# ===================== EXPORTED FUNCTIONS =====================
|
|
109
|
+
|
|
110
|
+
def password_gen() -> str:
|
|
111
|
+
"""Returns a safe random password."""
|
|
112
|
+
return generate_password()
|
|
113
|
+
|
|
114
|
+
def encrypt(raw_text: str, password: str) -> str:
|
|
115
|
+
"""
|
|
116
|
+
Encrypts text using AES-256 and custom bit rotation.
|
|
117
|
+
:param raw_text: The string message to be encrypted.
|
|
118
|
+
:param password: The secret key for encryption.
|
|
119
|
+
:return: A base64 encoded string of encrypted chunks.
|
|
120
|
+
"""
|
|
121
|
+
return _encrypt_text(raw_text, password)
|
|
122
|
+
|
|
123
|
+
def decrypt(encrypted_text: str, password: str) -> str:
|
|
124
|
+
"""
|
|
125
|
+
Decrypts text using AES-256 and custom bit rotation.
|
|
126
|
+
:param encrypted_text: The string message to be decrypted.
|
|
127
|
+
:param password: The secret key used during encryption.
|
|
128
|
+
:return: A plain decoded string.
|
|
129
|
+
"""
|
|
130
|
+
return _decrypt_text(encrypted_text, password)
|