This repository was archived by the owner on Jun 15, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathencoder.py
More file actions
Latest commit
86 lines (69 loc) · 2.92 KB
/
Copy pathencoder.py
File metadata and controls
86 lines (69 loc) · 2.92 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
key="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$%&+-.=?^{}"
encode_tuple=tuple(list(key))
defdecode_string(char_string):
globaldecode_dict
result=0
forcharinchar_string:
result*=74
result=result+key.find(char)
returnresult
defencode_number(num):
ifnum==0: return"0"
result=""
counter=0
whilenum>= (74**counter):
result+=key[num// (74**counter) %74]
counter+=1
returnresult[::-1]
if__name__=="__main__":
try:
importPySimpleGUIassg
exceptModuleNotFoundError:
try:
fromtermcolorimportcolored
importcolorama
colorama.init()
exceptModuleNotFoundError:
defcolored(text, _): returntext
print(colored("1)", "white"), colored("Decoder", "blue"))
print(colored("2)", "white"), colored("Encoder", "cyan"))
print(colored("3)", "white"), colored("Exit", "red"))
print(colored("Choose: ", "yellow"), end="")
inp=input()
ifinp=="1":
print(colored("Decoder", "blue"), colored("chosen\n", "yellow"))
print(colored("Write/paste string here: ", "green"), end="")
string=input()
string_dec=decode_string(string)
print()
print(colored("String decoded", "blue"))
print(colored(f"The original string is {string}", "blue"))
print(colored(f"The decoded number is {string_dec}\n", "blue"))
print()
elifinp=="2":
print(colored("Encoder", "cyan"), colored("chosen\n", "yellow"))
print(colored("Write/paste number here: ", "green"), end="")
number=input()
number_enc=encode_number(int(number))
print()
print(colored("Number encoded", "blue"))
print(colored(f"The original number is {number}", "blue"))
print(colored(f"The encoded string is {number_enc}", "blue"))
print()
elifinp=="3": pass
else:
print("You have chosen something that's not in the options!")
else:
layout= [[sg.Input(key="-DECODER IN-"), sg.Button("Decode", key="-DECODE-")],
[sg.Input(key="-ENCODER IN-"), sg.Button("Encode", key="-ENCODE-")],
[sg.Exit()]]
window=sg.Window("Encoder/Decoder", layout)
whileTrue:
event, values=window.read()
ifevent==sg.WIN_CLOSEDorevent=="Exit":
break
ifevent=="-DECODE-":
window["-ENCODER IN-"].update(decode_string(values["-DECODER IN-"]))
ifevent=="-ENCODE-":
window["-DECODER IN-"].update(encode_number(int(values["-ENCODER IN-"])))
window.close()