-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
33 lines (26 loc) · 1.04 KB
/
main.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
# DC Project
# 4B/5B Block Coding Technique
import random
validCodewords = {'0000': '11110', '0001': '01001', '0010': '10100', '0011': '10101',
'0100': '01010', '0101': '01011', '0110': '01110', '0111': '01111',
'1000': '10010', '1001': '10011', '1010': '10110', '1011': '10111',
'1100': '11010', '1101': '11011', '1110': '11100', '1111': '11101'}
print("Input 4 bit Dataword in binary :")
dataWord = input()
codeWord = validCodewords[dataWord]
print("corresponding codeword : ", codeWord)
errorPerc = random.randrange(100)
print(errorPerc)
if errorPerc > 7:
errorCodeWord = bin(random.randrange(31)).replace("0b", "")
errorCodeWord = errorCodeWord.zfill(5)
print("errorCodeword = ", errorCodeWord)
if errorCodeWord in validCodewords.values():
if errorCodeWord == codeWord:
print("LUCKY")
else:
print("Error Undetected")
else:
print("Error... Discarding Packet !...")
else:
print("PROPER TRANSMISSION")