linkpwn的解密工具

main.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
import tkinter as tk
from tkinter import messagebox, ttk
import os
import sys
import threading
import time
import cv2
from PIL import Image, ImageTk

# 导入外部解密模块
from xor1 import decrypt as xor_decrypt
from rc4 import decrypt as rc4_decrypt
from tea import decrypt1 as tea_decrypt
from xtea import decrypt1 as xtea_decrypt
from xxtea import decrypt as xxtea_decrypt

class UIBuilder:
"""UI组件构建工具类,用于创建统一风格的UI元素"""

@staticmethod
def create_title(parent, text, font_size=24, emoji="", bg="#1a1a2e"):
"""创建带表情符号的标题标签"""
title = tk.Label(
parent,
text=f"{emoji} {text} {emoji}",
font=("微软雅黑", font_size, "bold"),
bg=bg,
fg="white"
)
return title

@staticmethod
def create_button(parent, text, command, bg="#4ECDC4", font_size=12, emoji="", bg_hover="#3A9DA2"):
"""创建带悬停效果的按钮"""

def on_enter(e):
btn.config(bg=bg_hover)

def on_leave(e):
btn.config(bg=bg)

btn = tk.Button(
parent,
text=f"{emoji} {text} {emoji}" if emoji else text,
command=command,
font=("微软雅黑", font_size, "bold"),
bg=bg,
fg="white",
relief="flat",
bd=0
)
btn.bind("<Enter>", on_enter)
btn.bind("<Leave>", on_leave)
return btn

@staticmethod
def create_label(parent, text, font_size=12, fg="white", bg="#1a1a2e"):
"""创建统一风格的标签"""
label = tk.Label(
parent,
text=text,
font=("微软雅黑", font_size),
fg=fg,
bg=bg
)
return label

@staticmethod
def create_algorithm_info(parent, algorithm):
"""生成算法说明文本"""
info_texts = {
"xor": " XOR通过将密文与密钥进行异或操作来还原明文。\n"
"特点:速度快,适用于简单加密场景,但安全性较低。",
"rc4": "RC4是一种流加密算法,通过密钥生成伪随机字节流,与密文异或得到明文。\n"
" 特点:效率高,常用于网络数据加密,但存在安全漏洞需注意。",
"tea": "TEA是一种分组加密算法,使用64位分组和128位密钥。\n"
" 特点:结构简单,安全性较高,适用于资源受限环境。",
"xtea": "XTEA是TEA的扩展版本,改进了加密函数和密钥调度算法。\n"
" 特点:比TEA更抗密码分析,保持了算法简洁性。",
"xxtea": "XXTEA是另一种TEA扩展,进一步优化了加密强度和性能。\n"
" 特点:安全性高,适用于需要可靠加密的场景。"
}
info = tk.Label(
parent,
text=info_texts.get(algorithm, "暂无算法说明"),
font=("微软雅黑", 10),
fg="#CCCCCC",
bg="#1a1a2e",
justify=tk.LEFT,
wraplength=480
)
return info


class VideoBackground:
"""视频背景播放器(增强版,强制使用视频背景)"""

def __init__(self, parent, video_path, width=800, height=600):
self.parent = parent
self.width = width
self.height = height
self.video_path = os.path.abspath(video_path)
self.cap = None
self.video_label = tk.Label(parent, bg="black")
self.video_label.place(x=0, y=0, relwidth=1, relheight=1)
self.stop_flag = False
self.thread = None
self.running = True
self.error_count = 0

# 尝试多次加载视频,避免单次失败
self._init_video(force=True)

def _init_video(self, force=False):
"""初始化视频,支持强制重试"""
if not os.path.exists(self.video_path):
self._show_error(f"⚠️ 视频文件不存在:{self.video_path}")
self._create_error_overlay("视频文件缺失")
return

try:
self.cap = cv2.VideoCapture(self.video_path)
if not self.cap.isOpened():
raise RuntimeError(f"无法打开视频文件:{self.video_path}")

self.fps = self.cap.get(cv2.CAP_PROP_FPS) or 30
self.start_playback()
self.error_count = 0 # 重置错误计数

except Exception as e:
self.error_count += 1
self._show_error(f"⚠️ 视频打开错误(尝试 {self.error_count}/5):{str(e)}")

# 创建错误提示覆盖层
self._create_error_overlay(f"视频加载失败 {self.error_count}/5\n正在重试...")

# 尝试重新加载
if self.error_count <= 5 and force:
self.parent.after(3000, self._init_video)
else:
self._show_error("⚠️ 视频加载失败,使用默认背景", critical=True)

def _show_error(self, msg, critical=False):
"""显示错误信息"""
if DEBUG:
print(msg)
if critical:
messagebox.showerror("视频初始化失败", msg)

def _create_error_overlay(self, text):
"""创建错误提示覆盖层(半透明)"""
# 清除现有覆盖层
for widget in self.parent.winfo_children():
if isinstance(widget, tk.Canvas) and widget._name.startswith("error_overlay"):
widget.destroy()

# 创建新覆盖层(半透明黑色背景)
overlay = tk.Canvas(
self.parent,
width=self.width,
height=self.height,
bg="black",
bd=0,
highlightthickness=0
)
overlay.place(x=0, y=0)
overlay._name = "error_overlay"

# 半透明背景(30%透明度效果)
overlay.create_rectangle(
0, 0, self.width, self.height,
fill="black",
stipple="gray50"
)

# 错误文本
overlay.create_text(
self.width / 2, self.height / 2,
text=text,
fill="white",
font=("微软雅黑", 14, "bold")
)

def start_playback(self):
"""启动视频播放"""
if self.cap and not self.thread:
self.stop_flag = False
self.thread = threading.Thread(
target=self._update_video,
daemon=True
)
self.thread.start()

def stop_playback(self):
"""停止视频播放并释放资源"""
self.stop_flag = True
self.running = False
if self.thread and self.thread.is_alive():
self.thread.join(timeout=3)
if self.cap:
self.cap.release()
self.cap = None
if DEBUG:
print("🎥 视频播放已停止")

def _update_video(self):
"""视频帧更新循环"""
while self.running and not self.stop_flag:
try:
if not self.cap or not self.cap.isOpened():
# 尝试重新打开视频
self._init_video()
time.sleep(1)
continue

ret, frame = self.cap.read()
if not ret:
# 视频结束,从头开始
self.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
continue

# 处理视频帧
frame = cv2.resize(frame, (self.width, self.height))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
imgtk = ImageTk.PhotoImage(image=img)

# 更新显示
self.video_label.config(image=imgtk)
self.video_label.image = imgtk
time.sleep(1.0 / self.fps)

except Exception as e:
if DEBUG:
print(f"⚠️ 视频处理错误:{str(e)}")
time.sleep(1) # 错误后等待,避免CPU占用过高


class DecryptApp:
def __init__(self, root):
self.root = root
self.root.title("✨ linkpwn的解密工具 ✨")
self.root.geometry("800x600")
self.root.resizable(False, False)

# 设置窗口图标(示例图标路径,可替换为实际图标)
try:
root.iconbitmap("linkpwn.ico")
except:
if DEBUG:
print("⚠️ 图标加载失败,使用默认图标")

# 强制使用视频背景
video_path = "富士山的星空.mp4"
self.video_bg = VideoBackground(root, video_path)

# 创建欢迎界面(移除半透明遮罩)
self.create_welcome_screen()
self.create_status_bar()

# 注册窗口关闭事件
self.root.protocol("WM_DELETE_WINDOW", self.on_close)

def create_welcome_screen(self):
"""创建欢迎界面(仅保留视频背景上的UI元素)"""
# 欢迎标题(直接放置在视频背景上)
title = UIBuilder.create_title(
self.root,
"欢迎使用linkpwn的解密工具",
font_size=36,
emoji="✨",
bg=None # 透明背景
)
title.configure(fg="#5dade2") # 仅设置标题字体为浅蓝色
title.place(relx=0.5, rely=0.3, anchor=tk.CENTER)

# 进入按钮(直接放置在视频背景上)
enter_btn = UIBuilder.create_button(
self.root,
"进入解密工具",
self.open_algorithm_selector,
bg="#FF6B6B",
font_size=18,
emoji="🔓",
bg_hover="#FF4D4F"
)
enter_btn.place(relx=0.5, rely=0.5, anchor=tk.CENTER)

# 版权信息(直接放置在视频背景上)
copyright_text = UIBuilder.create_label(
self.root,
"© 2025 linkpwn. 保留所有权利.",
font_size=10,
fg="#999999",
bg=None # 透明背景
)
copyright_text.place(relx=0.5, rely=0.95, anchor=tk.CENTER)

def open_algorithm_selector(self):
"""打开算法选择窗口(优化背景显示)"""
self.algorithm_window = tk.Toplevel(self.root)
self.algorithm_window.title("💡 选择解密算法")
self.algorithm_window.geometry("600x400")
self.algorithm_window.resizable(False, False)
self.algorithm_window.transient(self.root)

# 创建半透明背景(仅在视频加载失败时显示)
bg = tk.Canvas(
self.algorithm_window,
width=600,
height=400,
bg="black",
highlightthickness=0
)
bg.pack(fill="both", expand=True)

# 标题
title = UIBuilder.create_title(
self.algorithm_window,
"选择解密算法",
font_size=24,
emoji="🔐"
)
title.place(relx=0.5, y=30, anchor=tk.CENTER)

# 分隔线
sep = tk.Frame(self.algorithm_window, height=2, bg="#4ECDC4")
sep.place(x=50, y=70, width=500)

# 算法按钮配置
algorithms = [
("xor", "❌ XOR解密"),
("rc4", "🔒 RC4解密"),
("tea", "🍵 TEA解密"),
("xtea", "🍵 XTEA解密"),
("xxtea", "🍵 XXTEA解密"),
]

for idx, (alg, text) in enumerate(algorithms):
btn = tk.Button(
self.algorithm_window,
text=text,
font=("微软雅黑", 14, "bold"),
bg="#4ECDC4",
fg="white",
relief="flat",
command=lambda a=alg: self.open_decrypt_window(a)
)
x = 100 if idx % 2 == 0 else 350
y = 120 + (idx // 2) * 80
btn.place(x=x, y=y, width=200, height=60)

def open_decrypt_window(self, algorithm):
"""打开解密窗口(优化背景显示)"""
# 销毁已存在的解密窗口
if hasattr(self, 'decrypt_window') and self.decrypt_window.winfo_exists():
self.decrypt_window.destroy()

self.decrypt_window = tk.Toplevel(self.root)
self.decrypt_window.title(f"💬 {self.get_algorithm_name(algorithm)}解密面板")
self.decrypt_window.geometry("600x450")
self.decrypt_window.resizable(False, False)
self.decrypt_window.transient(self.root)

panel = tk.Canvas(
self.decrypt_window,
width=600,
height=450,
bg="black",
highlightthickness=0,
bd=0,
relief="flat"
)
panel.pack(fill="both", expand=True)

# 标题
title = UIBuilder.create_title(
panel,
f"{self.get_algorithm_name(algorithm)}解密工具",
font_size=24,
bg="black"
)
title.place(relx=0.5, y=30, anchor=tk.CENTER)

# 分隔线
sep = tk.Frame(panel, height=2, bg="#4ECDC4")
sep.place(x=50, y=70, width=500)

# 算法说明
info = UIBuilder.create_algorithm_info(panel, algorithm)
info.place(x=50, y=90, width=500)

# 密文输入框
cipher_frame = tk.Frame(panel, bg="#1a1a2e")
cipher_frame.place(x=50, y=130, width=500, height=100)

cipher_label = UIBuilder.create_label(cipher_frame, "密文:", font_size=12)
cipher_label.pack(anchor="w", pady=(0, 5))

self.cipher_entry = tk.Text(
cipher_frame,
width=58,
height=3,
font=("Consolas", 12),
bg="#2a2a3e",
fg="white",
insertbackground="white",
relief="flat",
padx=10,
pady=5
)
self.cipher_entry.pack(fill="x")
self.cipher_entry.insert("1.0", self.get_default_ciphertext(algorithm))

# 密钥输入框
key_frame = tk.Frame(panel, bg="#1a1a2e")
key_frame.place(x=50, y=250, width=500, height=80)

key_label = UIBuilder.create_label(key_frame, "密钥:", font_size=12)
key_label.pack(anchor="w", pady=(0, 5))

self.key_entry = tk.Entry(
key_frame,
width=58,
font=("Consolas", 12),
bg="#2a2a3e",
fg="white",
insertbackground="white",
relief="flat"
)
self.key_entry.pack(fill="x")
self.key_entry.insert(0, self.get_default_key(algorithm))

# 按钮区域
btn_frame = tk.Frame(panel, bg="#1a1a2e")
btn_frame.place(x=50, y=340, width=500, height=40)

# 解密按钮
decrypt_btn = UIBuilder.create_button(
btn_frame,
"开始解密",
lambda: self.perform_decryption(algorithm),
bg="#FF6B6B",
font_size=14,
emoji="🔓"
)
decrypt_btn.pack(side="left", padx=(150, 0))

# 返回按钮
back_btn = UIBuilder.create_button(
btn_frame,
"返回",
self.decrypt_window.destroy,
bg="#666666",
font_size=10,
emoji="◀"
)
back_btn.pack(side="right", padx=(0, 20))

# 提示文本
hint = UIBuilder.create_label(
panel,
"💡 提示: 输入密文和密钥后点击解密按钮",
font_size=10,
fg="#999999"
)
hint.place(x=50, y=400, width=500)

def get_algorithm_name(self, algorithm):
"""获取算法名称"""
names = {
"xor": "XOR",
"rc4": "RC4",
"tea": "TEA",
"xtea": "XTEA",
"xxtea": "XXTEA"
}
return names.get(algorithm, algorithm.upper())

def get_default_ciphertext(self, algorithm):
"""获取默认密文"""
defaults = {
"xor": "1a2b3c4d5e6f",
"rc4": "730e7d1c4a1e",
"tea": "0123456789abcdef",
"xtea": "0123456789abcdef",
"xxtea": "0123456789abcdef"
}
return defaults.get(algorithm, "")

def get_default_key(self, algorithm):
"""获取默认密钥"""
defaults = {
"xor": "secret",
"rc4": "key12345",
"tea": "1234567890123456", # 16字节密钥
"xtea": "1234567890123456", # 16字节密钥
"xxtea": "1234567890123456" # 16字节密钥
}
return defaults.get(algorithm, "")

def create_status_bar(self):
"""创建状态栏"""
self.status = tk.Label(
self.root,
text="✨ 就绪 | linkpwn的解密工具 v1.0 | 安全解密 ✨",
bd=1,
relief=tk.SUNKEN,
anchor=tk.W,
font=("微软雅黑", 9),
fg="#CCCCCC",
bg="#1a1a2e"
)
self.status.pack(side=tk.BOTTOM, fill=tk.X)

def perform_decryption(self, algorithm):
"""执行解密操作"""
ciphertext = self.cipher_entry.get("1.0", tk.END).strip()
key = self.key_entry.get().strip()

if not ciphertext:
self.status.config(text="🛑 错误: 密文不能为空")
messagebox.showerror("😢 错误", "密文不能为空哦!")
return

if not key:
self.status.config(text="🛑 错误: 密钥不能为空")
messagebox.showerror("😢 错误", "密钥不能为空哦!")
return

self.status.config(text=f"🔄 使用{self.get_algorithm_name(algorithm)}解密中...")
threading.Thread(target=self._perform_decryption_thread, args=(ciphertext, key, algorithm), daemon=True).start()

def _perform_decryption_thread(self, ciphertext, key, algorithm):
"""在单独的线程中执行解密操作"""
try:
# 根据算法调用相应的解密函数
if algorithm == "xor":
result = xor_decrypt(ciphertext, key)
elif algorithm == "rc4":
result = rc4_decrypt(ciphertext, key)
elif algorithm == "tea":
result = tea_decrypt(ciphertext, key)
elif algorithm == "xtea":
result = xtea_decrypt(ciphertext, key)
elif algorithm == "xxtea":
result = xxtea_decrypt(ciphertext, key)
else:
result = f"🛑 不支持的算法: {algorithm}"

self.root.after(0, self._update_decryption_result, result)
except Exception as e:
error_msg = f"🛑 解密过程中发生错误: {str(e)}"
self.root.after(0, self._update_decryption_error, error_msg)

def _update_decryption_result(self, result):
"""更新解密结果"""
if "错误" in result or "Error" in result:
self.status.config(text=f"😢 解密失败: {result}")
messagebox.showerror("😢 解密失败", result)
else:
self.status.config(text="🎉 解密成功!")
self.show_result(result)

def _update_decryption_error(self, error_msg):
"""更新解密错误"""
self.status.config(text=error_msg)
messagebox.showerror("😢 错误", error_msg)

def show_result(self, plaintext):
"""显示解密结果窗口(优化背景显示)"""
try:
result_window = tk.Toplevel(self.decrypt_window)
result_window.title("🎁 解密结果")
result_window.geometry("500x300")
result_window.resizable(False, False)

bg = tk.Canvas(result_window, width=500, height=300, bg="#1a1a2e")
bg.pack(fill="both", expand=True)

title = UIBuilder.create_title(
bg,
"解密成功!",
font_size=18,
emoji="🎉",
bg="#1a1a2e"
)
title.place(relx=0.5, y=40, anchor=tk.CENTER)

result_frame = tk.Frame(bg, bg="#2a2a3e", bd=1, relief=tk.SUNKEN)
result_frame.place(x=25, y=70, width=450, height=180)

scrollbar = ttk.Scrollbar(result_frame)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)

result_text = tk.Text(
result_frame,
bg="#2a2a3e",
fg="white",
font=("Consolas", 11),
yscrollcommand=scrollbar.set,
wrap=tk.WORD,
padx=10,
pady=10
)
result_text.pack(fill="both", expand=True)
result_text.insert(tk.END, plaintext)
result_text.config(state=tk.DISABLED)
scrollbar.config(command=result_text.yview)

close_btn = UIBuilder.create_button(
bg,
"关闭",
result_window.destroy,
bg="#4ECDC4",
font_size=12
)
close_btn.place(relx=0.5, y=260, anchor=tk.CENTER)
except Exception as e:
messagebox.showerror("😢 错误", f"无法显示结果: {str(e)}")

def on_close(self):
"""窗口关闭时停止视频播放"""
if hasattr(self, 'video_bg') and self.video_bg:
self.video_bg.stop_playback()
self.root.destroy()


# === 程序入口 ===
DEBUG = True # 开发阶段设为True,发布时改为False

def run_app():
"""运行应用程序"""
root = tk.Tk()
# 设置窗口透明度(仅支持Windows和X11系统)
if sys.platform in ['win32', 'linux']:
root.attributes('-alpha', 0.95) # 95%透明度,保留视频背景效果
app = DecryptApp(root)
root.mainloop()

if __name__ == "__main__":
run_app()

beautiful.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import tkinter as tk

class UIBuilder:
"""UI构建器,负责创建美化后的界面元素"""

@staticmethod
def create_button(parent, text, command, bg="#4ECDC4", fg="white", font_size=12, emoji=""):
"""创建美化的按钮"""
full_text = f"{emoji} {text}" if emoji else text

# 安全的颜色调整函数
def darken_color(hex_color, factor=0.8):
"""降低颜色亮度"""
hex_color = hex_color.lstrip('#')
rgb = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4))
darkened = tuple(int(max(0, min(255, c * factor))) for c in rgb)
return f"#{darkened[0]:02x}{darkened[1]:02x}{darkened[2]:02x}"

return tk.Button(
parent,
text=full_text,
command=command,
font=("微软雅黑", font_size, "bold"),
bg=bg,
fg=fg,
activebackground=darken_color(bg),
relief="flat",
padx=15,
pady=5
)

@staticmethod
def create_label(parent, text, font_size=12, fg="white", bg="#1a1a2e", emoji=""):
"""创建美化的标签"""
full_text = f"{emoji} {text}" if emoji else text
return tk.Label(
parent,
text=full_text,
font=("微软雅黑", font_size),
fg=fg,
bg=bg
)

@staticmethod
def create_title(parent, text, font_size=24, fg="#4ECDC4", bg="#1a1a2e", emoji=""):
"""创建美化的标题"""
full_text = f"{emoji} {text} {emoji}" if emoji else text
return tk.Label(
parent,
text=full_text,
font=("微软雅黑", font_size, "bold"),
fg=fg,
bg=bg
)

@staticmethod
def create_algorithm_info(parent, algorithm):
"""创建算法说明信息"""
info_text = {
"xor": "❌ XOR加密: 最简单的加密算法,通过逐字节异或运算实现",
"rc4": "🔒 RC4: 流加密算法,广泛用于网络协议如SSL/TLS",
"tea": "🍵 TEA: 小型加密算法,使用64位数据块和128位密钥",
"xtea": "🍵 XTEA: TEA的改进版本,修复了一些安全漏洞",
"xxtea": "🍵 XXTEA: 更安全的TEA变体,处理变长数据块"
}

return tk.Label(
parent,
text=info_text.get(algorithm, f"❓ 未知算法: {algorithm}"),
font=("微软雅黑", 10),
fg="#FF9F1C",
bg="#1a1a2e"
)

rc4.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def decrypt(ciphertext, key):
"""RC4解密算法"""
try:
# 转换密文为字节
if all(c in '0123456789abcdefABCDEF' for c in ciphertext) and len(ciphertext) % 2 == 0:
cipher_bytes = bytes.fromhex(ciphertext)
else:
cipher_bytes = ciphertext.encode('utf-8')

key_bytes = key.encode('utf-8')

# RC4初始化
S = list(range(256))
j = 0
for i in range(256):
j = (j + S[i] + key_bytes[i % len(key_bytes)]) % 256
S[i], S[j] = S[j], S[i]

# 生成密钥流并解密
i = j = 0
decrypted = bytearray()

for byte in cipher_bytes:
i = (i + 1) % 256
j = (j + S[i]) % 256
S[i], S[j] = S[j], S[i]
k = S[(S[i] + S[j]) % 256]
decrypted.append(byte ^ k)

try:
return decrypted.decode('utf-8')
except UnicodeDecodeError:
return decrypted.hex()

except Exception as e:
return f"🛑 解密错误: {str(e)}"


# 使用示例
if __name__ == "__main__":
# 示例1: 解密十六进制格式的密文
ciphertext = "730e7d1c4a1e" # 示例密文(十六进制)
key = "key12345" # 密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

# 示例2: 解密字符串格式的密文
ciphertext = "encrypted_data" # 示例密文(字符串)
key = "mysecretkey" # 密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

tea.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def decrypt1(ciphertext, key):
"""TEA解密算法 - 修复32位无符号整数问题"""
try:
# 确保密钥长度为16字节
key_bytes = key.encode('utf-8')
if len(key_bytes) < 16:
key_bytes = key_bytes.ljust(16, b'\0')
elif len(key_bytes) > 16:
key_bytes = key_bytes[:16]

# 转换密文为字节
if all(c in '0123456789abcdefABCDEF' for c in ciphertext) and len(ciphertext) % 2 == 0:
cipher_bytes = bytes.fromhex(ciphertext)
else:
cipher_bytes = ciphertext.encode('utf-8')

# 确保数据长度是8的倍数
if len(cipher_bytes) % 8 != 0:
padding = 8 - (len(cipher_bytes) % 8)
cipher_bytes += b'\0' * padding

# 分块解密
decrypted = bytearray()
for i in range(0, len(cipher_bytes), 8):
block = cipher_bytes[i:i + 8]

# 解包为两个32位无符号整数
v0 = int.from_bytes(block[:4], 'big') & 0xFFFFFFFF
v1 = int.from_bytes(block[4:], 'big') & 0xFFFFFFFF
k = [int.from_bytes(key_bytes[i * 4:(i + 1) * 4], 'big') & 0xFFFFFFFF for i in range(4)]

# TEA解密过程
delta = 0x9E3779B9
sum_val = (delta * 32) & 0xFFFFFFFF # 确保初始值为32位无符号

# 辅助函数确保所有中间计算都在32位范围内
def tea_op(value, shift, add_val):
"""确保移位和加法操作保持在32位范围内"""
if shift > 0:
return ((value << shift) & 0xFFFFFFFF) + add_val
else:
return ((value >> -shift) & 0xFFFFFFFF) + add_val

for _ in range(32):
# 分解计算步骤,确保每步都在32位范围内
term1 = tea_op(v0, 4, k[2])
term2 = (v0 + sum_val) & 0xFFFFFFFF
term3 = tea_op(v0, -5, k[3])

v1 = (v1 - ((term1 ^ term2) ^ term3)) & 0xFFFFFFFF

term1 = tea_op(v1, 4, k[0])
term2 = (v1 + sum_val) & 0xFFFFFFFF
term3 = tea_op(v1, -5, k[1])

v0 = (v0 - ((term1 ^ term2) ^ term3)) & 0xFFFFFFFF
sum_val = (sum_val - delta) & 0xFFFFFFFF

# 再次确保v0和v1为非负数
v0 &= 0xFFFFFFFF
v1 &= 0xFFFFFFFF

# 打包解密结果(添加额外检查)
try:
decrypted_block = v0.to_bytes(4, 'big') + v1.to_bytes(4, 'big')
except OverflowError:
# 作为备用方案,直接处理32位值
decrypted_block = (v0 & 0xFFFFFFFF).to_bytes(4, 'big') + (v1 & 0xFFFFFFFF).to_bytes(4, 'big')

decrypted.extend(decrypted_block)

try:
# 尝试UTF-8解码,失败则返回HEX
return decrypted.decode('utf-8').rstrip('\0')
except UnicodeDecodeError:
return decrypted.hex()

except Exception as e:
return f"🛑 解密错误: {str(e)}"
# 使用示例
if __name__ == "__main__":
# 示例1: 解密十六进制格式的密文
ciphertext = "0123456789abcdef" # 示例密文(十六进制)
key = "1234567890123456" # 16字节密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

# 示例2: 解密字符串格式的密文
ciphertext = "encrypted_data" # 示例密文(字符串)
key = "mysecretkey1234" # 16字节密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

xor1.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# xor1.py

def xor_encrypt_decrypt(data, key):
"""
执行异或加密或解密操作。

:param data: 原始数据(字符串或 bytes)
:param key: 密钥(字符串或 bytes)
:return: 加密或解密后的 bytes 数据
"""
if isinstance(data, str):
data = data.encode('utf-8')
if isinstance(key, str):
key = key.encode('utf-8')

result = bytearray()
for i in range(len(data)):
key_byte = key[i % len(key)]
result.append(data[i] ^ key_byte)

return bytes(result)


def xor_decrypt(ciphertext, key):
"""
解密并返回可读格式。

优先尝试将结果解码为 UTF-8 字符串;
如果失败,则返回其十六进制表示。

:param ciphertext: 密文(bytes)
:param key: 解密密钥(字符串或 bytes)
:return: 可读明文(字符串)或错误信息
"""
try:
decrypted_bytes = xor_encrypt_decrypt(ciphertext, key)
try:
return decrypted_bytes.decode('utf-8') # 尝试作为文本返回
except UnicodeDecodeError:
return decrypted_bytes.hex() # 否则返回 hex 字符串
except Exception as e:
return f"🛑 解密错误: {str(e)}"


# 提供别名,方便外部调用 decrypt(data, key)
decrypt = xor_decrypt


# 测试用例(仅当直接运行此模块时执行)
if __name__ == "__main__":
test_key = "mysecretpassword"
original_text = "Hello, world! This is a test."

print("原文:", original_text)

encrypted_data = xor_encrypt_decrypt(original_text, test_key)
print("加密结果 (hex):", encrypted_data.hex())

decrypted_text = xor_decrypt(encrypted_data, test_key)
print("解密结果:", decrypted_text)

xtea.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def decrypt1(ciphertext, key):
"""XTEA解密算法"""
try:
# 确保密钥长度为16字节
key_bytes = key.encode('utf-8')
if len(key_bytes) < 16:
key_bytes = key_bytes.ljust(16, b'\0')
elif len(key_bytes) > 16:
key_bytes = key_bytes[:16]

# 转换密文为字节
if all(c in '0123456789abcdefABCDEF' for c in ciphertext) and len(ciphertext) % 2 == 0:
cipher_bytes = bytes.fromhex(ciphertext)
else:
cipher_bytes = ciphertext.encode('utf-8')

# 确保数据长度是8的倍数
if len(cipher_bytes) % 8 != 0:
padding = 8 - (len(cipher_bytes) % 8)
cipher_bytes += b'\0' * padding

# 分块解密
decrypted = bytearray()
for i in range(0, len(cipher_bytes), 8):
block = cipher_bytes[i:i+8]

# 解包为两个32位整数
v0, v1 = int.from_bytes(block[:4], 'big'), int.from_bytes(block[4:], 'big')
k = [int.from_bytes(key_bytes[i*4:(i+1)*4], 'big') for i in range(4)]

# XTEA解密过程
delta = 0x9E3779B9
sum_val = (delta * 32) & 0xFFFFFFFF

for _ in range(32):
v1 = ((v1 - (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum_val + k[(sum_val >> 11) & 3]))) & 0xFFFFFFFF
sum_val = (sum_val - delta) & 0xFFFFFFFF
v0 = ((v0 - (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum_val + k[sum_val & 3]))) & 0xFFFFFFFF

# 打包解密结果
decrypted_block = v0.to_bytes(4, 'big') + v1.to_bytes(4, 'big')
decrypted.extend(decrypted_block)

try:
return decrypted.decode('utf-8').rstrip('\0')
except UnicodeDecodeError:
return decrypted.hex()

except Exception as e:
return f"🛑 解密错误: {str(e)}"

xxtea.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def decrypt(ciphertext, key):
"""XXTEA解密算法"""
try:
# 确保密钥长度为16字节
key_bytes = key.encode('utf-8')
if len(key_bytes) < 16:
key_bytes = key_bytes.ljust(16, b'\0')
elif len(key_bytes) > 16:
key_bytes = key_bytes[:16]

# 转换密文为字节
if all(c in '0123456789abcdefABCDEF' for c in ciphertext) and len(ciphertext) % 2 == 0:
cipher_bytes = bytes.fromhex(ciphertext)
else:
cipher_bytes = ciphertext.encode('utf-8')

# 确保数据长度是4的倍数
if len(cipher_bytes) % 4 != 0:
padding = 4 - (len(cipher_bytes) % 4)
cipher_bytes += b'\0' * padding

# 解包为32位整数数组
n = len(cipher_bytes) // 4
v = [int.from_bytes(cipher_bytes[i*4:(i+1)*4], 'big') for i in range(n)]
k = [int.from_bytes(key_bytes[i*4:(i+1)*4], 'big') for i in range(4)]

# XXTEA解密过程
delta = 0x9E3779B9
q = 6 + 52 // n
sum_val = delta * q

for _ in range(q):
e = (sum_val >> 2) & 3
for p in range(n-1, 0, -1):
v[p] = (v[p] - (((v[p-1] << 4) ^ (v[p-1] >> 5)) + v[p-1]) ^ (sum_val + k[(p+e) % 4])) & 0xFFFFFFFF
v[0] = (v[0] - (((v[n-1] << 4) ^ (v[n-1] >> 5)) + v[n-1]) ^ (sum_val + k[e])) & 0xFFFFFFFF
sum_val = (sum_val - delta) & 0xFFFFFFFF

# 打包解密结果
decrypted = bytearray()
for num in v:
decrypted.extend(num.to_bytes(4, 'big'))

try:
return decrypted.decode('utf-8').rstrip('\0')
except UnicodeDecodeError:
return decrypted.hex()

except Exception as e:
return f"🛑 解密错误: {str(e)}"


# 使用示例
if __name__ == "__main__":
# 示例1: 解密十六进制格式的密文
ciphertext = "0123456789abcdef" # 示例密文(十六进制)
key = "1234567890123456" # 16字节密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

# 示例2: 解密字符串格式的密文
ciphertext = "encrypted_data" # 示例密文(字符串)
key = "mysecretkey1234" # 16字节密钥
plaintext = decrypt(ciphertext, key)
print(f"解密结果: {plaintext}")

package.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import os
import subprocess
import sys
from pathlib import Path

def check_dependencies():
"""检查并安装必要的依赖"""
required = [
'pyinstaller',
'opencv-python',
'pillow'
]

try:
import tkinter
except ImportError:
print("错误: 需要安装 tkinter (通常是 Python 自带)")
sys.exit(1)

for package in required:
try:
__import__(package)
except ImportError:
print(f"正在安装 {package}...")
subprocess.check_call([sys.executable, "-m", "pip", "install", package])

def build_exe():
"""构建 EXE 文件"""
# 获取当前脚本所在目录
base_dir = Path(__file__).parent

# 视频文件路径 (确保视频文件存在)
video_file = "富士山的星空.mp4"
if not (base_dir / video_file).exists():
print(f"错误: 视频文件 {video_file} 不存在!")
sys.exit(1)

# 图标文件路径 (可选)
icon_file = "linkpwn.ico"
icon_param = f"--icon={icon_file}" if (base_dir / icon_file).exists() else ""

# 加密模块列表
crypto_modules = ['xor1', 'rc4', 'tea', 'xtea', 'xxtea']

# 构建 PyInstaller 命令
cmd = [
'pyinstaller',
'--onefile', # 打包成单个文件
'--windowed', # 不显示控制台窗口
'--noconsole', # 同 --windowed
'--clean', # 清理临时文件
'--noconfirm', # 覆盖输出目录不提示
'--name=linkpwntool', # 输出文件名
'--add-data', f'{video_file};.', # 添加视频文件
]

# 添加图标 (如果存在)
if icon_param:
cmd.append(icon_param)

# 添加加密模块
for mod in crypto_modules:
mod_file = f"{mod}.py"
if (base_dir / mod_file).exists():
cmd.extend(['--add-data', f'{mod_file};.'])
else:
print(f"警告: 加密模块 {mod_file} 不存在!")

# 添加主程序
cmd.append('main.py')

# 执行打包命令
try:
print("开始打包...")
subprocess.check_call(cmd)
print("\n打包成功! EXE 文件位于 dist/ 目录")

# 复制视频文件到 dist 目录 (PyInstaller 的 --add-data 有时会失效)
if (base_dir / 'dist').exists():
import shutil
shutil.copy(base_dir / video_file, base_dir / 'dist' / video_file)
print(f"已复制视频文件到 dist 目录")
except subprocess.CalledProcessError as e:
print(f"\n打包失败: {e}")
except Exception as e:
print(f"\n发生错误: {str(e)}")

if __name__ == "__main__":
check_dependencies()
build_exe()

运行

1
python3 package.py  #mp4可自己选择把脚本中的mp4换成你自己mp4的名字;或者你直接把自己的MP4名字换成富士山的星空

运行成功在dist下有个exe,点击运行即可