aov-dec 1.0.0__py3-none-any.whl
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.
- aov_dec/__init__.py +135 -0
- aov_dec-1.0.0.dist-info/METADATA +47 -0
- aov_dec-1.0.0.dist-info/RECORD +5 -0
- aov_dec-1.0.0.dist-info/WHEEL +5 -0
- aov_dec-1.0.0.dist-info/top_level.txt +1 -0
aov_dec/__init__.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import zstandard as zstd
|
|
3
|
+
from Crypto.Cipher import AES
|
|
4
|
+
from Crypto.Util.Padding import pad, unpad
|
|
5
|
+
|
|
6
|
+
DICT_PATH = "dict"
|
|
7
|
+
ZSTD_DICT = open(DICT_PATH, "rb").read() if os.path.exists(DICT_PATH) else b""
|
|
8
|
+
|
|
9
|
+
class JG:
|
|
10
|
+
MAGIC = bytes.fromhex("22 4A 67")
|
|
11
|
+
|
|
12
|
+
@staticmethod
|
|
13
|
+
def get_name(file_path):
|
|
14
|
+
base = os.path.basename(file_path)
|
|
15
|
+
return os.path.splitext(base)[0]
|
|
16
|
+
|
|
17
|
+
@staticmethod
|
|
18
|
+
def _key(name):
|
|
19
|
+
h = 0
|
|
20
|
+
for ch in name:
|
|
21
|
+
c = ord(ch)
|
|
22
|
+
if 97 <= c <= 122:
|
|
23
|
+
c -= 32
|
|
24
|
+
h = ((h * 31) + c) & 0xFFFFFFFF
|
|
25
|
+
|
|
26
|
+
k = bytearray(bytes.fromhex("99 64 b1 b0 6b 03 8d 7f b7 7d b6 a7 54 90 8b 73"))
|
|
27
|
+
k0, k1, k2, k3 = (h & 0xFF, (h >> 8) & 0xFF, (h >> 16) & 0xFF, (h >> 24) & 0xFF)
|
|
28
|
+
for i in range(len(k)):
|
|
29
|
+
k[i] ^= (k0, k1, k2, k3)[i & 3]
|
|
30
|
+
return bytes(k)
|
|
31
|
+
|
|
32
|
+
@staticmethod
|
|
33
|
+
def decrypt(all_code, name):
|
|
34
|
+
key = JG._key(name)
|
|
35
|
+
ct = all_code[8:]
|
|
36
|
+
cipher = AES.new(key, AES.MODE_CBC, b"\x00" * 16)
|
|
37
|
+
try:
|
|
38
|
+
decrypted_data = cipher.decrypt(ct)
|
|
39
|
+
return unpad(decrypted_data, AES.block_size)
|
|
40
|
+
except (ValueError, KeyError):
|
|
41
|
+
raise ValueError("Giải mã mã hóa AES lỗi: Sai key hoặc dữ liệu hỏng.")
|
|
42
|
+
|
|
43
|
+
@staticmethod
|
|
44
|
+
def encrypt(all_code, name):
|
|
45
|
+
key = JG._key(name)
|
|
46
|
+
original_len = len(all_code)
|
|
47
|
+
pt_padded = pad(all_code, AES.block_size)
|
|
48
|
+
|
|
49
|
+
cipher = AES.new(key, AES.MODE_CBC, b"\x00" * 16)
|
|
50
|
+
ct = cipher.encrypt(pt_padded)
|
|
51
|
+
hdr = JG.MAGIC + b"\x00" + original_len.to_bytes(4, "little")
|
|
52
|
+
return hdr + ct
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ZSTD:
|
|
56
|
+
@staticmethod
|
|
57
|
+
def dec(all_code):
|
|
58
|
+
compressed_data = all_code[8:]
|
|
59
|
+
dctx = zstd.ZstdDecompressor(dict_data=zstd.ZstdCompressionDict(ZSTD_DICT))
|
|
60
|
+
return dctx.decompress(compressed_data)
|
|
61
|
+
|
|
62
|
+
@staticmethod
|
|
63
|
+
def com(all_code):
|
|
64
|
+
cctx = zstd.ZstdCompressor(level=17, dict_data=zstd.ZstdCompressionDict(ZSTD_DICT))
|
|
65
|
+
compressed = bytearray(cctx.compress(all_code))
|
|
66
|
+
compressed[0:0] = len(all_code).to_bytes(4, byteorder="little")
|
|
67
|
+
compressed[0:0] = b"\"J\x00\xef"
|
|
68
|
+
return compressed
|
|
69
|
+
|
|
70
|
+
def auto(file_path):
|
|
71
|
+
try:
|
|
72
|
+
with open(file_path, "rb") as f:
|
|
73
|
+
all_code = f.read()
|
|
74
|
+
|
|
75
|
+
if not all_code:
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
if all_code[0:3] == JG.MAGIC:
|
|
79
|
+
new_code = JG.decrypt(all_code, JG.get_name(file_path))
|
|
80
|
+
with open(file_path, "wb") as f: f.write(new_code)
|
|
81
|
+
print("\33[1;32mDECRYPT AES\33[1;39m", file_path)
|
|
82
|
+
elif all_code[0:4] == b"\"J\x00\xef":
|
|
83
|
+
new_code = ZSTD.dec(all_code)
|
|
84
|
+
with open(file_path, "wb") as f: f.write(new_code)
|
|
85
|
+
print("\33[1;32mDECOMPRESS ZSTD\33[1;39m", file_path)
|
|
86
|
+
else:
|
|
87
|
+
new_code = ZSTD.com(all_code)
|
|
88
|
+
with open(file_path, "wb") as f: f.write(new_code)
|
|
89
|
+
print("\33[1;36mCOMPRESS ZSTD\33[1;39m", file_path)
|
|
90
|
+
|
|
91
|
+
except Exception as e:
|
|
92
|
+
print(f"\33[1;31mERROR {file_path}: {e}\33[1;39m")
|
|
93
|
+
|
|
94
|
+
def mode(file_path, mode):
|
|
95
|
+
try:
|
|
96
|
+
with open(file_path, "rb") as f:
|
|
97
|
+
all_code = f.read()
|
|
98
|
+
|
|
99
|
+
if not all_code:
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
if mode == "COM_ZSTD":
|
|
103
|
+
if all_code[0:4] == b"\"J\x00\xef":
|
|
104
|
+
raise ValueError("File đã được nén ZSTD")
|
|
105
|
+
new_code = ZSTD.com(all_code)
|
|
106
|
+
msg = "\33[1;36mCOMPRESS ZSTD\33[1;39m"
|
|
107
|
+
|
|
108
|
+
elif mode == "DEC_ZSTD":
|
|
109
|
+
if all_code[0:4] == b"\"J\x00\xef":
|
|
110
|
+
new_code = ZSTD.dec(all_code)
|
|
111
|
+
msg = "\33[1;32mDECOMPRESS ZSTD\33[1;39m"
|
|
112
|
+
else:
|
|
113
|
+
raise ValueError("File không phải là file ZSTD")
|
|
114
|
+
|
|
115
|
+
elif mode == "ENC_AES":
|
|
116
|
+
if all_code[0:3] == JG.MAGIC:
|
|
117
|
+
raise ValueError("File đã được mã hóa AES")
|
|
118
|
+
new_code = JG.encrypt(all_code, JG.get_name(file_path))
|
|
119
|
+
msg = "\33[1;36mENCRYPT AES\33[1;39m"
|
|
120
|
+
|
|
121
|
+
elif mode == "DEC_AES":
|
|
122
|
+
if all_code[0:3] == JG.MAGIC:
|
|
123
|
+
new_code = JG.decrypt(all_code, JG.get_name(file_path))
|
|
124
|
+
msg = "\33[1;32mDECRYPT AES\33[1;39m"
|
|
125
|
+
else:
|
|
126
|
+
raise ValueError("File không phải là file AES")
|
|
127
|
+
else:
|
|
128
|
+
return
|
|
129
|
+
|
|
130
|
+
with open(file_path, "wb") as f:
|
|
131
|
+
f.write(new_code)
|
|
132
|
+
print(msg, file_path)
|
|
133
|
+
|
|
134
|
+
except Exception as e:
|
|
135
|
+
print(f"\33[1;31mERROR {file_path}: {e}\33[1;39m")
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: aov-dec
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Compress/Decompress AOV File
|
|
5
|
+
Author: Vinh LC
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: zstandard
|
|
9
|
+
Requires-Dist: pycryptodome
|
|
10
|
+
|
|
11
|
+
# 🛠️ File Processor (ZSTD & AES)
|
|
12
|
+
|
|
13
|
+
Một công cụ Python nhỏ gọn hỗ trợ nén, giải nén dữ liệu bằng **ZSTD** và mã hóa, giải mã bảo mật bằng **AES**.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🚀 Tính năng chính
|
|
18
|
+
|
|
19
|
+
* ⚡ **Nén & Giải nén tốc độ cao:** Sử dụng thuật toán `ZSTD`.
|
|
20
|
+
* 🔒 **Bảo mật dữ liệu:** Mã hóa và giải mã với chuẩn mã hóa nâng cao `AES`.
|
|
21
|
+
* 🎨 **Giao diện dòng lệnh trực quan:** Hỗ trợ hiển thị màu sắc (ANSI escape codes) giúp dễ dàng theo dõi.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🛠️ Hướng dẫn Sử dụng
|
|
26
|
+
|
|
27
|
+
Để xem hướng dẫn nhanh trong terminal, bạn có thể gọi hàm `help()` có sẵn trong công cụ.
|
|
28
|
+
|
|
29
|
+
### 1. Chế độ Tự động (Auto Mode)
|
|
30
|
+
Tự động phát hiện và xử lý file dựa trên định dạng hoặc cấu trúc sẵn có.
|
|
31
|
+
```python
|
|
32
|
+
auto(file_path)
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. Chế độ Thủ công (Mode)
|
|
36
|
+
Xử lý file theo chế độ đã chọn
|
|
37
|
+
|
|
38
|
+
| Tùy chọn Mode | Loại tác vụ | Mô tả chi tiết |
|
|
39
|
+
| :--- | :--- | :--- |
|
|
40
|
+
| **`COM_ZSTD`** | `Compression` | Nén tệp tin đích bằng thuật toán ZSTD để giảm dung lượng. |
|
|
41
|
+
| **`DEC_ZSTD`** | `Decompression` | Giải nén tệp tin đã nén bằng ZSTD về trạng thái gốc ban đầu. |
|
|
42
|
+
| **`ENC_AES`** | `Encryption` | Mã hóa bảo mật tệp tin bằng thuật toán mã hóa AES. |
|
|
43
|
+
| **`DEC_AES`** | `Decryption` | Giải mã tệp tin đã được mã hóa bằng AES trở lại bình thường. |
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
mode(file_path, mode)
|
|
47
|
+
```
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
aov_dec/__init__.py,sha256=SApVFvyKdmmG20_j2_3CmU8ZNRydHQZ6VND07MUbp2g,4705
|
|
2
|
+
aov_dec-1.0.0.dist-info/METADATA,sha256=8kp-Vx5oI9q3B9LLpP18iUDxIELlK8vjaG92EOisNfA,1744
|
|
3
|
+
aov_dec-1.0.0.dist-info/WHEEL,sha256=BNRMDyzLkkcmlv0J8ppDQkk2VED33SesJDynr9ED1gc,91
|
|
4
|
+
aov_dec-1.0.0.dist-info/top_level.txt,sha256=of9hsAfl6EJZ9QKVSiCOGWNn2iUp205Uj0Aq1YBqFeA,8
|
|
5
|
+
aov_dec-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
aov_dec
|