-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdec.py
More file actions
32 lines (24 loc) · 844 Bytes
/
Copy pathdec.py
File metadata and controls
32 lines (24 loc) · 844 Bytes
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
'''
Python module to convert binary string into message.
The message or each block is divided into 6-bit blocks and the eqivalent integer number is obtained
if the number is between 1-26 --> converted to Character
between 27-36 --> converted to number
37 --> '.'
38 --> ' '
'''
Decode = []
def decode(message):
i = 0
while(i < len(message)):
con = message[i:i+6]
dec = int(''.join(map(str,con)),2)
if 1<=dec<=26:
Decode.append(chr(dec+96))
elif 27<=dec<=36:
Decode.append(str(dec-27))
elif dec == 37:
Decode.append('.')
elif dec == 38:
Decode.append(' ')
i = i + 6
return (''.join(map(str,Decode))) #return the final converted message.