-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitStuffing8bits.py
52 lines (40 loc) · 1.17 KB
/
BitStuffing8bits.py
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
print("Message Encodor/Decodor")
def encoder():
emsg=[]
value=0
message=input("Enter the message in binary -")
for i in message:
if i=='1':
emsg.append(1)
value=value+1
if value==5:
emsg.append('0')
value=0
elif i=='0':
emsg.append(0)
print("the encoded message is "+''.join([str(elem) for elem in emsg]))
def decoder():
emsg=[]
value=0
i=0
message=input("Enter the message in binary - ")
while i < len(message):
if message[i]=='1':
emsg.append(1)
value=value+1
if value==5:
i=i+1
value=0
elif message[i]=='0':
emsg.append(0)
i=i+1
print("the encoded message is "+''.join([str(elem) for elem in emsg]))
while(True):
print("\n1.Encode the message ")
print("2.Decode the message ")
choice=int(input("Enter your choice -"))
if choice==1:
encoder()
elif choice==2:
decoder()
else:print("Enter the correct choice")