Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
32 views2 pages

2b) Crc-16 Sender and Receiver

Uploaded by

babludablu2511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views2 pages

2b) Crc-16 Sender and Receiver

Uploaded by

babludablu2511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

def xor(a, b):

# Perform XOR operation between two binary strings


result = []
for i in range(1, len(b)):
if a[i] == b[i]:
result.append('0')
else:
result.append('1')
return ''.join(result)

def mod2div(dividend, divisor):


# Perform Modulo-2 division (XOR-based division)
pick = len(divisor)
tmp = dividend[0:pick]

while pick < len(dividend):


if tmp[0] == '1':
tmp = xor(divisor, tmp) + dividend[pick]
else:
tmp = xor('0' * pick, tmp) + dividend[pick]
pick += 1

if tmp[0] == '1':
tmp = xor(divisor, tmp)
else:
tmp = xor('0' * pick, tmp)

return tmp

def crc_sender(data, generator):


# Append zero bits to the data equal to the length of the generator minus 1
padded_data = data + '0' * (len(generator) - 1)
remainder = mod2div(padded_data, generator)
codeword = data + remainder
return codeword

def crc_receiver(codeword, generator):


# Perform Modulo-2 division on the received codeword
remainder = mod2div(codeword, generator)
return remainder == '0' * (len(generator) - 1)

# CRC-16 Polynomial (X^16 + X^15 + X^2 + 1)


CRC_16 = "11000000000000101"

# Get user input for data


data = input("Enter the binary data to be transmitted: ")

# Sender Side: Calculate CRC-16 codeword


crc16_codeword = crc_sender(data, CRC_16)
print(f"\nSender Side:")
print(f"Original Data: {data}")
print(f"CRC-16 Polynomial: {CRC_16}")
print(f"CRC-16 Codeword (Sent): {crc16_codeword}")

# Simulate transmission (for simplicity, assume the received codeword is the same)
received_codeword = input("\nEnter the received codeword: ")

# Receiver Side: Check if the received codeword is error-free


is_error_free = crc_receiver(received_codeword, CRC_16)
print(f"\nReceiver Side:")
print(f"Received Codeword: {received_codeword}")
if is_error_free:
print("No error detected. The received data is correct.")
else:
print("Error detected in the received codeword.")

You might also like