forked from Yukon51/CTF_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
16进制文本转换ascii.py
100 lines (88 loc) · 3.29 KB
/
16进制文本转换ascii.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
import os
import win32con
import win32clipboard
from rich.table import Table
from rich.console import Console
from prettytable import PrettyTable
console = Console()
base_dir = os.path.dirname(os.path.abspath(__file__))
def get_text():
win32clipboard.OpenClipboard()
d = win32clipboard.GetClipboardData(win32con.CF_TEXT)
win32clipboard.CloseClipboard()
return d.decode('GBK')
def int2str(byte_list, is_add=True):
ret = []
if is_add:
for i in range(256):
add_text, flag = "", 0
for number in byte_list:
num = number+i
if 31 < num < 127:
add_text += chr(num)
else:
add_text += "~"
flag = 1
ret.append([f"+{i}", add_text, flag])
else:
for i in range(1, 256):
add_text, flag = "", 0
for number in byte_list:
num = number-i
if 31 < num < 127:
add_text += chr(num)
else:
add_text += "~"
flag = 1
ret.append([f"-{i}", add_text, flag])
return ret
def show_table(ret, is_all=False):
table = PrettyTable(field_names=["Offset", "Text"])
table.title = "Byxs20 Hex Tools"
for data in ret:
if data[-1] == 0 or is_all:
table.add_row([data[0], f"{data[1]}"])
console.print(table)
def xor_str(cipher_text: str):
ret = []
for i in range(1, 256):
add_text, flag = "", 0
for number in cipher_text.encode():
num = number ^ i
if 31 < num < 127:
add_text += chr(num)
else:
add_text += "~"
flag = 1
ret.append([f"^{i}", add_text, flag])
return ret
def show_xor_table(ret, is_all=False):
table = PrettyTable(field_names=["Offset", "Text"])
table.title = "Byxs20 Xor Tools"
for data in ret:
if data[-1] == 0 or is_all:
table.add_row([data[0], f"{data[1]}"])
console.print(table)
if __name__ == "__main__":
text = get_text()
console.print("Byxs20 Str Tools:", style="bold blue")
try:
byte_list = [int(text[i:i+2], 16) for i in range(0, len(text), 2)]
ret = int2str(byte_list, is_add=False)
ret.extend(int2str(byte_list, is_add=True))
console.print("[-] 逐字节增加减少0xFF: ", style="bold #00ffff")
show_table(ret, is_all=False)
if console.input("[bold blue]是否需要全部输出? [/]([bold red]y[/]/[bold green]N[/]): ") in ["Y", "y"]:
show_table(ret, is_all=True)
except ValueError:
console.print("[-] 输入的字符串不符合逐字节增加减少!", style="bold #00ffff")
try:
console.print("\n[-] 逐字节异或0xFF: ", style="bold #00ffff")
ret = xor_str(text)
show_xor_table(ret, is_all=False)
if console.input("[bold blue]是否需要全部输出? [/]([bold red]y[/]/[bold green]N[/]): ") in ["Y", "y"]:
show_table(ret, is_all=True)
except Exception:
console.print("[-] 输入的字符串不符合逐字节异或!", style="bold #00ffff")
os.system("pause")
# c8e9aca0c3f4e6e5f2a1a0d4e8e5a0e6ece1e7a0e9f3baa0e6ece1e7fbf7e5e6e5efe9e4eae7efe5e4f3e6e9eff2f0e5e6e4e6e7e7e6e4f3e5fd