Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,87 +1 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import numpy as np
|
| 4 |
-
import hashlib
|
| 5 |
-
|
| 6 |
-
# --- PHẦN SECRET ES & STRETCH KEY GIỮ NGUYÊN ---
|
| 7 |
-
SECRET_CODE = os.getenv("ES")
|
| 8 |
-
exec_context = {}
|
| 9 |
-
encrypt_fn = None
|
| 10 |
-
decrypt_fn = None
|
| 11 |
-
|
| 12 |
-
if SECRET_CODE:
|
| 13 |
-
try:
|
| 14 |
-
exec(SECRET_CODE, exec_context)
|
| 15 |
-
encrypt_fn = exec_context.get('transform_byte')
|
| 16 |
-
decrypt_fn = exec_context.get('untransform_byte')
|
| 17 |
-
except Exception as e:
|
| 18 |
-
print(f"Lỗi Secret ES: {e}")
|
| 19 |
-
|
| 20 |
-
def stretch_key(password, salt=b"MinhDuc_Zero_Trust_Protocol"):
|
| 21 |
-
key = password.encode() + salt
|
| 22 |
-
for _ in range(10000):
|
| 23 |
-
key = hashlib.sha512(key).digest()
|
| 24 |
-
return key[:32]
|
| 25 |
-
|
| 26 |
-
# --- HÀM XỬ LÝ CHÍNH ---
|
| 27 |
-
def process_file(file, password, mode, progress=gr.Progress()):
|
| 28 |
-
if not encrypt_fn: return None, "❌ Secret ES chưa nạp!"
|
| 29 |
-
|
| 30 |
-
master_key = np.frombuffer(stretch_key(password), dtype=np.uint8)
|
| 31 |
-
input_path = file.name
|
| 32 |
-
original_full_name = os.path.basename(input_path)
|
| 33 |
-
|
| 34 |
-
if mode == "Mã hóa":
|
| 35 |
-
output_name = original_full_name + ".impossible"
|
| 36 |
-
else:
|
| 37 |
-
output_name = original_full_name.replace(".impossible", "") if original_full_name.endswith(".impossible") else "rebuilt_" + original_full_name
|
| 38 |
-
|
| 39 |
-
output_path = os.path.join(os.path.dirname(input_path), output_name)
|
| 40 |
-
file_size = os.path.getsize(input_path)
|
| 41 |
-
chunk_size = 4 * 1024 * 1024
|
| 42 |
-
bytes_processed = 0
|
| 43 |
-
fn = encrypt_fn if mode == "Mã hóa" else decrypt_fn
|
| 44 |
-
|
| 45 |
-
try:
|
| 46 |
-
with open(input_path, 'rb') as f_in, open(output_path, 'wb') as f_out:
|
| 47 |
-
while True:
|
| 48 |
-
chunk = f_in.read(chunk_size)
|
| 49 |
-
if not chunk: break
|
| 50 |
-
|
| 51 |
-
data_arr = np.frombuffer(chunk, dtype=np.uint8)
|
| 52 |
-
indices = np.arange(bytes_processed, bytes_processed + len(data_arr), dtype=np.uint64)
|
| 53 |
-
key_chunk = master_key[indices % 32]
|
| 54 |
-
|
| 55 |
-
processed_chunk = fn(data_arr, key_chunk, indices)
|
| 56 |
-
f_out.write(processed_chunk.astype(np.uint8).tobytes())
|
| 57 |
-
|
| 58 |
-
bytes_processed += len(chunk)
|
| 59 |
-
# Cập nhật tiến trình cho hàng đợi thấy
|
| 60 |
-
progress(bytes_processed / file_size, desc=f"Đang {mode}...")
|
| 61 |
-
|
| 62 |
-
return output_path, f"✅ Thành công: {output_name}"
|
| 63 |
-
except Exception as e:
|
| 64 |
-
return None, f"❌ Lỗi: {str(e)}"
|
| 65 |
-
|
| 66 |
-
# --- GIAO DIỆN VỚI QUEUE LOGIC ---
|
| 67 |
-
with gr.Blocks(theme=gr.themes.Monochrome(), title="Titanium4S Vault") as demo:
|
| 68 |
-
gr.Markdown("# 🛡️ Titanium4S - Professional Vault")
|
| 69 |
-
|
| 70 |
-
with gr.Row():
|
| 71 |
-
with gr.Column():
|
| 72 |
-
inp_file = gr.File(label="Input File")
|
| 73 |
-
inp_pass = gr.Textbox(label="Secret Key", type="password")
|
| 74 |
-
inp_mode = gr.Radio(["Mã hóa", "Giải mã"], label="Mode", value="Mã hóa")
|
| 75 |
-
btn = gr.Button("EXECUTE", variant="primary")
|
| 76 |
-
with gr.Column():
|
| 77 |
-
out_file = gr.File(label="Result")
|
| 78 |
-
status = gr.Textbox(label="Status", interactive=False)
|
| 79 |
-
|
| 80 |
-
btn.click(process_file, [inp_file, inp_pass, inp_mode], [out_file, status])
|
| 81 |
-
|
| 82 |
-
# KÍCH HOẠT QUEUE (HÀNG ĐỢI)
|
| 83 |
-
# default_concurrency_limit: số file xử lý cùng lúc (thường để 1-2 để tránh crash RAM)
|
| 84 |
-
demo.queue(default_concurrency_limit=1)
|
| 85 |
-
|
| 86 |
-
if __name__ == "__main__":
|
| 87 |
-
demo.launch()
|
|
|
|
| 1 |
+
import os, gradio as gr, numpy as np, hashlib; S, C = os.getenv("ES"), {}; exec(S, C) if S else None; E, D = C.get('transform_byte'), C.get('untransform_byte'); K = lambda p, s=b"MinhDuc_Zero_Trust_Protocol": (lambda k: [k := hashlib.sha512(k).digest() for _ in range(10000)][-1][:32])(p.encode() + s); V = lambda f, w, m, pr=gr.Progress(): (lambda mk, ip, fn, is_e: (lambda on, op, fs, cs, bp, func: (lambda: (None, f"Err: {str(e)}") if not E else ([(da := np.frombuffer(f_in.read(cs), dtype=np.uint8), ix := np.arange(bp, bp + len(da), dtype=np.uint64), kc := mk[ix % 32], f_out.write(func(da, kc, ix).astype(np.uint8).tobytes()), bp := bp + len(da), pr(bp/fs, desc="Processing")) for _ in iter(int, 1) if (da := np.frombuffer(f_in.read(cs), dtype=np.uint8)).size > 0] or (op, f"Done: {on}")))(original_full_name + ".impossible" if is_e else (original_full_name.replace(".impossible", "") if original_full_name.endswith(".impossible") else "rebuilt_" + original_full_name), os.path.join(os.path.dirname(input_path), output_name), os.path.getsize(input_path), 4*1024*1024, 0, E if is_e else D))(np.frombuffer(K(w), dtype=np.uint8), f.name, os.path.basename(f.name), m == "M\u00e3 h\u00f3\u0061"); (lambda: [gr.Markdown("# 🛡️ T4S GHOST"), [[i1 := gr.File(), i2 := gr.Textbox(type="password"), i3 := gr.Radio(["M\u00e3 h\u00f3\u0061", "Gi\u1ea3i m\u00e3"], value="M\u00e3 h\u00f3\u0061"), b := gr.Button("EXEC")], [o1 := gr.File(), o2 := gr.Textbox()]], b.click(V, [i1, i2, i3], [o1, o2])] if gr.Blocks(theme=gr.themes.Monochrome()).queue(1).launch() else None)()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|