tuhbooh commited on
Commit
cf3f3db
·
verified ·
1 Parent(s): 2f3f31c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -55
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 (Giữ nguyê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: print(f"Error: {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Ỉ SIÊU CẤP ---
25
  class T4S_PDF(FPDF):
26
  def header(self):
27
- # Vẽ một thanh header màu xanh đậm
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", 20)
32
- self.cell(0, 10, "TITANIUM4S - QUANTUM SECURE PROTOCOL", ln=True, align="C")
33
- self.set_font("Helvetica", "", 10)
34
- self.cell(0, 5, "Official Security Audit & Ownership Certificate", ln=True, align="C")
35
 
36
  def footer(self):
37
- self.set_y(-20)
38
- self.set_font("Helvetica", "I", 8)
39
- self.set_text_color(150, 150, 150)
40
- self.cell(0, 10, f"Issued by Titanium4S Zero-Trust Engine | Record ID: {hashlib.md5(str(datetime.now()).encode()).hexdigest()[:10].upper()}", align="C")
 
 
 
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. PHẦN THÔNG TIN FILE (Bố cục cột)
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. PROTECTED ASSET IDENTITY", ln=True)
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, "Filename:", 0); pdf.set_font("Helvetica", "B", 12); pdf.cell(0, 10, file_name, ln=True)
56
- pdf.set_font("Helvetica", "", 12)
57
- pdf.cell(40, 10, "SHA-256 Fingerprint:", 0); pdf.set_font("Courier", "B", 10); pdf.cell(0, 10, sha_hash, ln=True)
58
 
59
- # 2. PHẦN CÔNG NGHỆ (Technology Overview)
60
  pdf.ln(10)
 
61
  pdf.set_font("Helvetica", "B", 16)
62
- pdf.cell(0, 10, "2. TECHNOLOGY SPECIFICATION", ln=True)
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
- "- Key Stretching: SHA-512 (10,000 Iterations) - Immunity against ASIC/GPU brute-force.\n"
69
- "- Cipher Core: Vectorized Non-linear Transformation (Proprietary ES Logic).\n"
70
- "- Protocol: Zero-Knowledge Proof (The system never stores your secret key)."
71
  )
72
  pdf.multi_cell(0, 7, tech_info)
73
 
74
- # 3. PHẦN MẬT KHẨU & CẢNH BÁO (Làm nổi bật)
75
  pdf.ln(10)
76
- pdf.set_fill_color(254, 249, 231) # Màu vàng nhạt cho vùng password
77
- pdf.rect(10, pdf.get_y(), 277, 25, 'F')
78
  pdf.set_y(pdf.get_y() + 5)
79
- pdf.set_font("Helvetica", "B", 14); pdf.set_text_color(192, 57, 43)
80
- pdf.cell(0, 5, "CRITICAL: YOUR SECRET KEY RECORD", ln=True, align="C")
81
- pdf.set_font("Courier", "B", 18)
82
- pdf.cell(0, 12, password, ln=True, align="C")
83
 
84
- # 4. LỜI NHẮC CỦA TITANIUM4S
85
  pdf.ln(15)
86
  pdf.set_text_color(44, 62, 80)
87
  pdf.set_font("Helvetica", "B", 12)
88
- pdf.cell(0, 10, "SECURITY COMPLIANCE & WARNINGS:", ln=True)
89
  pdf.set_font("Helvetica", "", 10)
90
  pdf.multi_cell(0, 6, (
91
- "1. This PDF is the only proof of ownership. If deleted, there is no backup on any server.\n"
92
- "2. The file .impossible is mathematically locked. Brute-forcing would take centuries with current hardware.\n"
93
- "3. Please store this certificate in a secure vault or an offline encrypted drive."
94
  ))
95
 
96
- # Đóng dấu "TOP SECRET" giả lập
97
- pdf.set_font("Helvetica", "B", 50)
98
- pdf.set_text_color(231, 76, 60)
99
- pdf.rotate(25, 200, 150)
100
- pdf.text(180, 180, "TOP SECRET")
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 Error!"
 
 
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"Processing {mode}...")
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], "✅ Đã hóa & Xuất hồ sơ bảo mật!"
143
 
144
- return [output_path], "✅ Giải mã thành công!"
145
- except Exception as e: return None, f"❌ Lỗi: {str(e)}"
 
146
 
147
- # --- 4. GIAO DIỆN ---
148
- with gr.Blocks(theme=gr.themes.Monochrome(), title="Titanium4S Vault") as demo:
149
- gr.Markdown("# 🛡️ Titanium4S - Ultimate Audit Edition")
 
 
 
150
  with gr.Row():
151
  with gr.Column():
152
- inp_file = gr.File(label="Target File")
153
- inp_pass = gr.Textbox(label="Secret Key", type="password")
154
- inp_mode = gr.Radio(["Mã hóa", "Giải mã"], label="Mode", value="Mã hóa")
155
- btn = gr.Button("INITIALIZE PROTOCOL", variant="primary")
156
  with gr.Column():
157
- out_files = gr.File(label="Output Assets", file_count="multiple")
158
- status = gr.Textbox(label="System Status", interactive=False)
159
- btn.click(process_file, [inp_file, inp_pass, inp_mode], [out_files, status])
 
 
160
 
161
- demo.queue(1).launch(ssr_mode=False)
 
 
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 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ì ( 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 (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 tấm 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' 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()