-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.py
More file actions
94 lines (73 loc) · 2.49 KB
/
Copy pathdecode.py
File metadata and controls
94 lines (73 loc) · 2.49 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
import base64
import main
def base64_decode(base64_message):
base64_bytes = base64_message.encode('ascii')
message_bytes = base64.b64decode(base64_bytes)
message = message_bytes.decode('ascii')
return message
def hex_decode(message):
bytes_object = bytes.fromhex(message)
ascii_string = bytes_object.decode("ASCII")
return ascii_string
def BinaryToDecimal(binary):
decimal, i, n = 0, 0, 0
while binary != 0:
dec = binary % 10
decimal = decimal + dec * pow(2, i)
binary = binary // 10
i += 1
return decimal
def bin_decode(bin_data):
binary_int = int(bin_data, 2)
byte_number = binary_int.bit_length() + 7 // 8
binary_array = binary_int.to_bytes(byte_number, "big")
ascii_text = binary_array.decode()
return ascii_text
def decode_base64():
msg = input("type a message to be decoded: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after Base 64 encoding : " + base64_decode(msg))
decoding()
def decode_hex():
msg = input("type a message to be decoded: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after hexadecimal decoding : " + str(hex_decode(msg)))
decoding()
def decode_binary():
msg = input("type a binary sequance to be decoded: ")
# printing original string
print("The original string is : " + str(msg))
# printing result
print("The string after binary conversion : " + bin_decode(msg))
decoding()
def decoding():
print("1: Base64 ")
print("2: Hex ")
#("3: Binary ")
print("4: Return ")
while True:
choix_1_1 = int(input("please type your choice : "))
try:
if choix_1_1 in [1, 2, 3, 4]:
if choix_1_1 == 1:
decode_base64()
break
if choix_1_1 == 2:
decode_hex()
break
if choix_1_1 == 3:
#decode_binary()
decoding()
break
elif choix_1_1 == 4:
main.encode_decode()
break
else:
print("Please provide integer between 1 and 4")
except ValueError:
print("Please provide integer")
break