Repository navigation
Expand file tree
/
Copy pathinteractive.py
More file actions
176 lines (148 loc) · 4.68 KB
/
Copy pathinteractive.py
File metadata and controls
176 lines (148 loc) · 4.68 KB
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
import base64 as bs
from rich import box
from rich.align import Align
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Prompt
from rich.rule import Rule
from rich.table import Table
from rich.text import Text
console = Console()
def print_banner():
console.clear()
banner = Text()
banner.append("██████████ ████████ ██ ██ ██████████\n",style="bold cyan",)
banner.append(" ██ ██ ██ ██ ██\n",style="bold cyan",)
banner.append(" ██ ██████ ██ ██\n",style="bold blue",)
banner.append(" ██ ██ ██ ██ ██\n",style="bold blue",)
banner.append(" ██ ████████ ██ ██ ██\n\n",style="bold magenta",)
banner.append(" Base64 • Text Encoder • Text Decoder ",style="dim white",)
console.print(
Panel(
Align.center(banner),
border_style="cyan",
box=box.DOUBLE_EDGE,
)
)
def divider(title=""):
console.print(
Rule(
title,
style="cyan",
)
)
def success(message):
console.print(f"\n[bold green]✔[/bold green] {message}\n")
def error(message):
console.print(f"\n[bold red]✘[/bold red] {message}\n")
def info(message):
console.print(f"[bold yellow]ℹ[/bold yellow] {message}")
def encode_text(text):
encoded = bs.b64encode(text.encode("utf-8"))
return encoded.decode("utf-8")
def decode_text(encoded_text):
decoded = bs.b64decode(encoded_text,validate=True)
return decoded.decode("utf-8")
def menu():
table = Table(
title="Main Menu",
title_style="bold cyan",
box=box.DOUBLE_EDGE,
border_style="cyan",
padding=(0, 2),
)
table.add_column(
"Option",
justify="center",
style="bold yellow",
)
table.add_column("Action",style="green",)
table.add_row("1","🔒 Encode Text",)
table.add_row("2","🔓 Decode Text",)
table.add_row("3","ℹ About",)
table.add_row("0","🚪 Exit",)
console.print(table)
def encode_menu():
divider("🔒 Encode Text")
text = Prompt.ask("[bold cyan]Enter text[/bold cyan]")
try:
result = encode_text(text)
console.print(
Panel(
result,
title="Encoded Base64",
border_style="green",
box=box.ROUNDED,
)
)
except Exception as e: # noqa: BLE001
error(str(e))
def decode_menu():
divider("🔓 Decode Text")
encoded_text = Prompt.ask("[bold cyan]Enter Base64 text[/bold cyan]")
try:
result = decode_text(encoded_text)
console.print(
Panel(
result,
title="Decoded Text",
border_style="green",
box=box.ROUNDED,
)
)
except Exception: # noqa: BLE001
error("Invalid Base64 input.")
def about():
divider("ℹ About Toolkit")
table = Table(
show_header=True,
header_style="bold cyan",
box=box.ROUNDED,
border_style="cyan",
)
table.add_column("Property",style="yellow",)
table.add_column("Value",style="green",)
table.add_row("Purpose","Base64 Text Encoding & Decoding",)
table.add_row("Encoding","Base64",)
table.add_row("Character Encoding","UTF-8",)
table.add_row("Encode Method","Base64",)
table.add_row("Decode Validation","Strict",)
table.add_row("Language","Python",)
table.add_row("UI","Rich CLI",)
console.print(table)
def main():
while True:
print_banner()
menu()
choice = Prompt.ask(
"\n[bold cyan]Select Option[/bold cyan]",
choices=["1", "2", "3", "0"],
default="1",
)
if choice == "1":
encode_menu()
elif choice == "2":
decode_menu()
elif choice == "3":
about()
elif choice == "0":
console.print()
console.print(
Panel(
Align.center(
Text(
"See You Soon! | Stay safe, stay secure. 🕵️",
style="bold cyan",
)
),
border_style="magenta",
box=box.DOUBLE_EDGE,
)
)
break
Prompt.ask(
"\n[dim]Press Enter to return to menu…[/dim]",
default="",
)
if __name__ == "__main__":
main()