-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (33 loc) · 1.06 KB
/
main.py
File metadata and controls
40 lines (33 loc) · 1.06 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
import binascii
output = ''
print('[1] convert to binary')
print('[2] covnert to hexadecimals')
print('[3] convert to octodecimals')
print('[4] decode to hexadecimal to text')
option = input('select option: ')
while not (option == '1' or option == '2' or option == '3' or option == '4'):
print('invalid input')
option = input('select option: ')
# text to ascii to binary
if option == '1':
string = input('enter string to cipher: ')
for char in string:
char_num = bin(ord(char))
output += char_num[2:]
# text to ascii to hexadecimals
elif option == '2':
string = input('enter string to cipher: ')
for char in string:
char_num = hex(ord(char))
output += char_num[2:]
# text to ascii to octodecimals
elif option == '3':
string = input('enter string to cipher: ')
for char in range(len(string)):
char_num = oct(ord(string[char]))
output += char_num[2:]
# deciphering
elif option == '4':
string = input('enter string to decipher: ')
output = binascii.unhexlify(string).decode()
print('value: ', output)