Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,15 +5,17 @@ import hashlib
|
|
| 5 |
from fpdf import FPDF
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
-
# --- 1. SETUP THUẬT TOÁN (
|
| 9 |
SECRET_CODE = os.getenv("ES")
|
| 10 |
exec_context = {}
|
| 11 |
encrypt_fn = decrypt_fn = None
|
|
|
|
| 12 |
if SECRET_CODE:
|
| 13 |
try:
|
| 14 |
exec(SECRET_CODE, exec_context)
|
| 15 |
encrypt_fn, decrypt_fn = exec_context.get('transform_byte'), exec_context.get('untransform_byte')
|
| 16 |
-
except Exception as e:
|
|
|
|
| 17 |
|
| 18 |
def get_file_sha256(file_path):
|
| 19 |
h = hashlib.sha256()
|
|
@@ -21,83 +23,87 @@ def get_file_sha256(file_path):
|
|
| 21 |
while chunk := f.read(8192): h.update(chunk)
|
| 22 |
return h.hexdigest()
|
| 23 |
|
| 24 |
-
# --- 2. HÀM THIẾT KẾ CHỨNG CHỈ
|
| 25 |
class T4S_PDF(FPDF):
|
| 26 |
def header(self):
|
| 27 |
-
#
|
| 28 |
self.set_fill_color(44, 62, 80)
|
| 29 |
self.rect(0, 0, 297, 30, 'F')
|
| 30 |
self.set_text_color(255, 255, 255)
|
| 31 |
-
self.set_font("Helvetica", "B",
|
| 32 |
-
self.cell(0,
|
| 33 |
-
self.set_font("Helvetica", "", 10)
|
| 34 |
-
self.cell(0, 5, "
|
| 35 |
|
| 36 |
def footer(self):
|
| 37 |
-
self.set_y(-
|
| 38 |
-
self.set_font("Helvetica", "I",
|
| 39 |
-
self.set_text_color(
|
| 40 |
-
self.cell(0,
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def create_detailed_pdf(file_name, sha_hash, password, output_path):
|
| 43 |
pdf = T4S_PDF(orientation="L", unit="mm", format="A4")
|
| 44 |
pdf.add_page()
|
| 45 |
|
| 46 |
-
# 1.
|
| 47 |
pdf.ln(10)
|
| 48 |
pdf.set_text_color(0, 0, 0)
|
| 49 |
pdf.set_font("Helvetica", "B", 16)
|
| 50 |
-
pdf.cell(0, 10, "1.
|
| 51 |
pdf.set_line_width(0.5); pdf.set_draw_color(44, 62, 80); pdf.line(10, pdf.get_y(), 287, pdf.get_y())
|
| 52 |
|
| 53 |
pdf.ln(5)
|
| 54 |
pdf.set_font("Helvetica", "", 12)
|
| 55 |
-
pdf.cell(40, 10, "
|
| 56 |
-
pdf.set_font("Helvetica", "",
|
| 57 |
-
pdf.cell(
|
| 58 |
|
| 59 |
-
# 2.
|
| 60 |
pdf.ln(10)
|
|
|
|
| 61 |
pdf.set_font("Helvetica", "B", 16)
|
| 62 |
-
pdf.cell(0, 10, "2.
|
| 63 |
pdf.set_line_width(0.5); pdf.line(10, pdf.get_y(), 287, pdf.get_y())
|
| 64 |
|
| 65 |
pdf.ln(5)
|
| 66 |
pdf.set_font("Helvetica", "", 11)
|
| 67 |
tech_info = (
|
| 68 |
-
"-
|
| 69 |
-
"-
|
| 70 |
-
"-
|
| 71 |
)
|
| 72 |
pdf.multi_cell(0, 7, tech_info)
|
| 73 |
|
| 74 |
-
# 3.
|
| 75 |
pdf.ln(10)
|
| 76 |
-
pdf.set_fill_color(
|
| 77 |
-
pdf.rect(10, pdf.get_y(), 277,
|
| 78 |
pdf.set_y(pdf.get_y() + 5)
|
| 79 |
-
pdf.set_font("Helvetica", "B",
|
| 80 |
-
pdf.cell(0, 5, "
|
| 81 |
-
pdf.set_font("Courier", "B",
|
| 82 |
-
pdf.cell(0,
|
| 83 |
|
| 84 |
-
# 4. LỜI NHẮC
|
| 85 |
pdf.ln(15)
|
| 86 |
pdf.set_text_color(44, 62, 80)
|
| 87 |
pdf.set_font("Helvetica", "B", 12)
|
| 88 |
-
pdf.cell(0, 10, "
|
| 89 |
pdf.set_font("Helvetica", "", 10)
|
| 90 |
pdf.multi_cell(0, 6, (
|
| 91 |
-
"1.
|
| 92 |
-
"2.
|
| 93 |
-
"3.
|
| 94 |
))
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
pdf.set_font("Helvetica", "B",
|
| 98 |
-
pdf.set_text_color(
|
| 99 |
-
pdf.rotate(
|
| 100 |
-
pdf.text(
|
| 101 |
pdf.rotate(0)
|
| 102 |
|
| 103 |
pdf.output(output_path)
|
|
@@ -110,7 +116,9 @@ def stretch_key(password):
|
|
| 110 |
return key[:32]
|
| 111 |
|
| 112 |
def process_file(file, password, mode, progress=gr.Progress()):
|
| 113 |
-
if not encrypt_fn: return None, "❌ Secret ES
|
|
|
|
|
|
|
| 114 |
master_key = np.frombuffer(stretch_key(password), dtype=np.uint8)
|
| 115 |
input_path = file.name
|
| 116 |
original_name = os.path.basename(input_path)
|
|
@@ -134,28 +142,35 @@ def process_file(file, password, mode, progress=gr.Progress()):
|
|
| 134 |
key_chunk = master_key[indices % 32]
|
| 135 |
f_out.write(fn(data_arr, key_chunk, indices).astype(np.uint8).tobytes())
|
| 136 |
bytes_processed += len(chunk)
|
| 137 |
-
progress(bytes_processed / file_size, desc=f"
|
| 138 |
|
| 139 |
if is_encrypt:
|
| 140 |
pdf_path = os.path.join(os.path.dirname(input_path), f"Audit_{original_name}.pdf")
|
| 141 |
create_detailed_pdf(original_name, file_hash, password, pdf_path)
|
| 142 |
-
return [output_path, pdf_path], "✅
|
| 143 |
|
| 144 |
-
return [output_path], "✅ Giải mã thành công!"
|
| 145 |
-
except Exception as e:
|
|
|
|
| 146 |
|
| 147 |
-
# --- 4. GIAO DIỆN ---
|
| 148 |
-
with gr.Blocks(theme=gr.themes.
|
| 149 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
| 150 |
with gr.Row():
|
| 151 |
with gr.Column():
|
| 152 |
-
inp_file = gr.File(label="
|
| 153 |
-
inp_pass = gr.Textbox(label="
|
| 154 |
-
inp_mode = gr.Radio(["Mã hóa", "Giải mã"], label="
|
| 155 |
-
btn = gr.Button("
|
| 156 |
with gr.Column():
|
| 157 |
-
out_files = gr.File(label="
|
| 158 |
-
status = gr.Textbox(label="
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
| 161 |
-
|
|
|
|
|
|
| 5 |
from fpdf import FPDF
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
+
# --- 1. SETUP THUẬT TOÁN (Core Logic) ---
|
| 9 |
SECRET_CODE = os.getenv("ES")
|
| 10 |
exec_context = {}
|
| 11 |
encrypt_fn = decrypt_fn = None
|
| 12 |
+
|
| 13 |
if SECRET_CODE:
|
| 14 |
try:
|
| 15 |
exec(SECRET_CODE, exec_context)
|
| 16 |
encrypt_fn, decrypt_fn = exec_context.get('transform_byte'), exec_context.get('untransform_byte')
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Error loading ES Logic: {e}")
|
| 19 |
|
| 20 |
def get_file_sha256(file_path):
|
| 21 |
h = hashlib.sha256()
|
|
|
|
| 23 |
while chunk := f.read(8192): h.update(chunk)
|
| 24 |
return h.hexdigest()
|
| 25 |
|
| 26 |
+
# --- 2. HÀM THIẾT KẾ CHỨNG CHỈ (BẢN FRIENDLY BY MINH ĐỨC) ---
|
| 27 |
class T4S_PDF(FPDF):
|
| 28 |
def header(self):
|
| 29 |
+
# Header phong cách hiện đại
|
| 30 |
self.set_fill_color(44, 62, 80)
|
| 31 |
self.rect(0, 0, 297, 30, 'F')
|
| 32 |
self.set_text_color(255, 255, 255)
|
| 33 |
+
self.set_font("Helvetica", "B", 22)
|
| 34 |
+
self.cell(0, 15, "TITANIUM4S - BIÊN BẢN 'PHONG ẤN' FILE", ln=True, align="C")
|
| 35 |
+
self.set_font("Helvetica", "I", 10)
|
| 36 |
+
self.cell(0, 5, "App này làm từ tâm huyết của Minh Đức á! <3", ln=True, align="C")
|
| 37 |
|
| 38 |
def footer(self):
|
| 39 |
+
self.set_y(-25)
|
| 40 |
+
self.set_font("Helvetica", "I", 9)
|
| 41 |
+
self.set_text_color(100, 100, 100)
|
| 42 |
+
self.cell(0, 5, "Cần gì cứ nhắn mình: truonghoangminhduc123@gmail.com", ln=True, align="C")
|
| 43 |
+
self.set_text_color(44, 62, 80)
|
| 44 |
+
self.set_font("Helvetica", "B", 10)
|
| 45 |
+
self.cell(0, 7, "Thấy xịn thì đừng quên: dub.sh/donatemepls ;)", ln=True, align="C")
|
| 46 |
|
| 47 |
def create_detailed_pdf(file_name, sha_hash, password, output_path):
|
| 48 |
pdf = T4S_PDF(orientation="L", unit="mm", format="A4")
|
| 49 |
pdf.add_page()
|
| 50 |
|
| 51 |
+
# 1. THÔNG TIN FILE
|
| 52 |
pdf.ln(10)
|
| 53 |
pdf.set_text_color(0, 0, 0)
|
| 54 |
pdf.set_font("Helvetica", "B", 16)
|
| 55 |
+
pdf.cell(0, 10, "1. ĐỐI TƯỢNG ĐÃ ĐƯỢC 'XỬ LÝ'", ln=True)
|
| 56 |
pdf.set_line_width(0.5); pdf.set_draw_color(44, 62, 80); pdf.line(10, pdf.get_y(), 287, pdf.get_y())
|
| 57 |
|
| 58 |
pdf.ln(5)
|
| 59 |
pdf.set_font("Helvetica", "", 12)
|
| 60 |
+
pdf.cell(40, 10, "Tên file gốc:", 0); pdf.set_font("Helvetica", "B", 12); pdf.cell(0, 10, file_name, ln=True)
|
| 61 |
+
pdf.set_font("Helvetica", "I", 10); pdf.set_text_color(100, 100, 100)
|
| 62 |
+
pdf.cell(0, 5, "À umm, file của bạn giờ thành bột mì (mã hóa) hết rồi nhé :/", ln=True)
|
| 63 |
|
| 64 |
+
# 2. CÔNG NGHỆ
|
| 65 |
pdf.ln(10)
|
| 66 |
+
pdf.set_text_color(0, 0, 0)
|
| 67 |
pdf.set_font("Helvetica", "B", 16)
|
| 68 |
+
pdf.cell(0, 10, "2. 'MA THUẬT' ĐẰNG SAU", ln=True)
|
| 69 |
pdf.set_line_width(0.5); pdf.line(10, pdf.get_y(), 287, pdf.get_y())
|
| 70 |
|
| 71 |
pdf.ln(5)
|
| 72 |
pdf.set_font("Helvetica", "", 11)
|
| 73 |
tech_info = (
|
| 74 |
+
"- Bam! SHA-512 chạy 10,000 vòng để hacker 'khóc thét'.\n"
|
| 75 |
+
"- Vectorized Non-linear: Chế độ xào nấu dữ liệu siêu cấp của Minh Đức.\n"
|
| 76 |
+
"- Zero-Knowledge: Mình không giữ khóa của bạn đâu, mất là mình cũng chịu thua!"
|
| 77 |
)
|
| 78 |
pdf.multi_cell(0, 7, tech_info)
|
| 79 |
|
| 80 |
+
# 3. MẬT KHẨU
|
| 81 |
pdf.ln(10)
|
| 82 |
+
pdf.set_fill_color(240, 240, 240)
|
| 83 |
+
pdf.rect(10, pdf.get_y(), 277, 30, 'F')
|
| 84 |
pdf.set_y(pdf.get_y() + 5)
|
| 85 |
+
pdf.set_font("Helvetica", "B", 13); pdf.set_text_color(231, 76, 60)
|
| 86 |
+
pdf.cell(0, 5, "MẬT KHẨU ĐÂY NÈ (CẤM QUÊN - QUÊN LÀ NHỊN):", ln=True, align="C")
|
| 87 |
+
pdf.set_font("Courier", "B", 20)
|
| 88 |
+
pdf.cell(0, 15, f">> {password} <<", ln=True, align="C")
|
| 89 |
|
| 90 |
+
# 4. LỜI NHẮC NHỞ
|
| 91 |
pdf.ln(15)
|
| 92 |
pdf.set_text_color(44, 62, 80)
|
| 93 |
pdf.set_font("Helvetica", "B", 12)
|
| 94 |
+
pdf.cell(0, 10, "MẤY CÁI NÀY QUAN TRỌNG NÈ:", ln=True)
|
| 95 |
pdf.set_font("Helvetica", "", 10)
|
| 96 |
pdf.multi_cell(0, 6, (
|
| 97 |
+
"1. Cái file PDF này là tấm vé duy nhất để bạn tìm lại dữ liệu. Giữ cho kỹ nha!\n"
|
| 98 |
+
"2. File .impossible bị khóa bằng toán học rồi, siêu máy tính giải cũng mất vài thế kỷ.\n"
|
| 99 |
+
"3. Nên cất chứng chỉ này vào ổ cứng rời hoặc in ra rồi giấu dưới gối cho chắc."
|
| 100 |
))
|
| 101 |
|
| 102 |
+
# Dấu ấn riêng
|
| 103 |
+
pdf.set_font("Helvetica", "B", 40)
|
| 104 |
+
pdf.set_text_color(200, 200, 200)
|
| 105 |
+
pdf.rotate(20, 200, 150)
|
| 106 |
+
pdf.text(170, 185, "MINH DUC SECURED")
|
| 107 |
pdf.rotate(0)
|
| 108 |
|
| 109 |
pdf.output(output_path)
|
|
|
|
| 116 |
return key[:32]
|
| 117 |
|
| 118 |
def process_file(file, password, mode, progress=gr.Progress()):
|
| 119 |
+
if not encrypt_fn: return None, "❌ Lỗi Secret ES! Kiểm tra biến môi trường."
|
| 120 |
+
if not password: return None, "⚠️ Nhập mật khẩu đã rồi tính tiếp bạn ơi!"
|
| 121 |
+
|
| 122 |
master_key = np.frombuffer(stretch_key(password), dtype=np.uint8)
|
| 123 |
input_path = file.name
|
| 124 |
original_name = os.path.basename(input_path)
|
|
|
|
| 142 |
key_chunk = master_key[indices % 32]
|
| 143 |
f_out.write(fn(data_arr, key_chunk, indices).astype(np.uint8).tobytes())
|
| 144 |
bytes_processed += len(chunk)
|
| 145 |
+
progress(bytes_processed / file_size, desc=f"Đang {mode}...")
|
| 146 |
|
| 147 |
if is_encrypt:
|
| 148 |
pdf_path = os.path.join(os.path.dirname(input_path), f"Audit_{original_name}.pdf")
|
| 149 |
create_detailed_pdf(original_name, file_hash, password, pdf_path)
|
| 150 |
+
return [output_path, pdf_path], "✅ Xong! File đã 'hóa vàng' và có luôn hồ sơ bảo mật nhé!"
|
| 151 |
|
| 152 |
+
return [output_path], "✅ Giải mã thành công! Chào mừng file đã quay trở lại."
|
| 153 |
+
except Exception as e:
|
| 154 |
+
return None, f"❌ Có biến rồi: {str(e)}"
|
| 155 |
|
| 156 |
+
# --- 4. GIAO DIỆN GRADIO ---
|
| 157 |
+
with gr.Blocks(theme=gr.themes.Soft(), title="Titanium4S Vault") as demo:
|
| 158 |
+
gr.Markdown("""
|
| 159 |
+
# 🛡️ Titanium4S - Ultimate Audit Edition
|
| 160 |
+
### Hệ thống bảo mật "Made by Minh Đức" - An toàn tuyệt đối, thân thiện tối đa.
|
| 161 |
+
""")
|
| 162 |
with gr.Row():
|
| 163 |
with gr.Column():
|
| 164 |
+
inp_file = gr.File(label="Kéo file vào đây nè")
|
| 165 |
+
inp_pass = gr.Textbox(label="Mật khẩu bí mật (Đừng để ai thấy nha)", type="password", placeholder="Nhập pass tại đây...")
|
| 166 |
+
inp_mode = gr.Radio(["Mã hóa", "Giải mã"], label="Bạn muốn làm gì?", value="Mã hóa")
|
| 167 |
+
btn = gr.Button("KÍCH HOẠT GIAO THỨC", variant="primary")
|
| 168 |
with gr.Column():
|
| 169 |
+
out_files = gr.File(label="Kết quả thu được", file_count="multiple")
|
| 170 |
+
status = gr.Textbox(label="Trạng thái hệ thống", interactive=False)
|
| 171 |
+
|
| 172 |
+
gr.Markdown("---")
|
| 173 |
+
gr.Markdown("© 2026 Titanium4S Project | Liên hệ: truonghoangminhduc123@gmail.com | Donate: dub.sh/donatemepls")
|
| 174 |
|
| 175 |
+
if __name__ == "__main__":
|
| 176 |
+
demo.queue().launch()
|