WCN PBL Codes
WCN PBL Codes
Question 2: Write a program to detect an error at the receiver end using CRC method
(Python)
def detect_crc_error(received_data, divisor):
data = received_data
1
# Append zeros to the received data to match the length of the divisor
data += '0' * (len(divisor) - 1)
data = list(data) # Convert data to a list for easy manipulation
# Get user input for the received data and the same divisor used for encoding
received_data_input = input("Enter the received data (binary): ")
divisor_input = input("Enter the same divisor used for encoding (binary): ")
Q3 write a program to identifying the types of error like single bit error, multiple bit error and
burst error with user defined input. also what will be the output
def identify_error_type(received_data):
# Count the number of '1's in the received data
2
ones_count = received_data.count('1')
if ones_count == 1:
return "Single Bit Error"
elif ones_count > 1:
return "Multiple Bit Error"
else:
return "No Error (or Burst Error)"
Question 4: Write a program to generate a code using the checksum method with user-
friendly input and user-defined data input (Python)
def generate_checksum(data):
# Calculate the checksum as the sum of ASCII values of characters in the data
checksum = sum(ord(char) for char in data)
return checksum
3
print("Checksum:", checksum)
Question 5: Write a program to detect an error at the receiver end using the checksum
method (Python)
def detect_checksum_error(received_data, received_checksum):
# Calculate the checksum from the received data
calculated_checksum = sum(ord(char) for char in received_data)
if calculated_checksum == received_checksum:
return "No error detected."
else:
return "Error detected."
# Get user input for the received data and received checksum
received_data_input = input("Enter the received data: ")
received_checksum_input = int(input("Enter the received checksum: "))
QUES6.>write a program to generate a code using Hamming method with user friendly input
with user defined input.
def generate_hamming_code(data):
4
# Calculate the number of parity bits needed (r)
r=0
while 2 ** r < len(data) + r + 1:
r += 1
# Initialize the Hamming code with parity bits as '?' (to be filled)
hamming_code = list(data) + ['?'] * r
return ''.join(hamming_code)
QUES6.>write a program to generate a code using Hamming method with user friendly input
with user defined input. what will be the output
def generate_hamming_code(data):
5
# Calculate the number of parity bits needed (r)
r=0
while 2**r < len(data) + r + 1:
r += 1
return ''.join(hamming_code)
6
# Generate the Hamming code
hamming_code = generate_hamming_code(data_input)
print("Hamming Code:", hamming_code)
QUES7.> write a program to detect and correct an error at receiver end using Hamming
method. what will be the output
def detect_correct_hamming_error(received_data):
# Convert received data to a list
received_code = list(received_data)
7
# Correct the error
for position in error_positions:
if received_code[position - 1] == '0':
received_code[position - 1] = '1'
else:
received_code[position - 1] = '0'
return corrected_data
Question 8: Write a program for stop-and-wait protocol, generating a code using the
Hamming method with user-friendly input and user-defined input.
import random
8
# This is a simplified example. In practice, you'd need to implement the Hamming
encoding algorithm.
hamming_code = data # Placeholder for simplicity
return hamming_code
return received_data
# Simulate transmission (in a real network, you'd send data over a network)
received_data = sender_hamming_code
received_data = receiver(received_data)
9
print(f"Receiver: After error simulation: {received_data}")
if __name__ == "__main":
main()
Question 9: Implementation of data link layer framing method for bit stuffing in any
language.
def sender_bit_stuffing(data):
start_delimiter = '01111110' # Start-of-frame delimiter
end_delimiter = '01111110' # End-of-frame delimiter
stuffed_data = start_delimiter
stuffed_data += data.replace('011111', '0111110') # Bit stuffing: Replace '011111' with
'0111110'
stuffed_data += end_delimiter
return stuffed_data
def receiver_bit_unstuffing(stuffed_data):
# Remove start delimiter and end delimiter
data = stuffed_data[8:-8]
# Bit unstuffing: Replace '0111110' with '011111'
data = data.replace('0111110', '011111')
return data
10
# Main function to demonstrate bit stuffing and unstuffing
def main():
data = input("Enter data to be transmitted: ")
stuffed_data = sender_bit_stuffing(data)
print("Stuffed Data:", stuffed_data)
received_data = receiver_bit_unstuffing(stuffed_data)
print("Received Data:", received_data)
if __name__ == "__main__":
main()
import time
# Simulated receiver
def receiver(received_frame):
if received_frame:
return "ACK"
else:
return "NAK"
11
# Simulated sender
def sender(data):
frame_to_send = data
while frame_to_send:
acknowledgment = receiver(frame_to_send)
if acknowledgment == "ACK":
else:
# Main function
def main():
sender(data_to_send)
if __name__ == "__main__":
main()
12
Question 11: Implementation of stop-and-wait ARQ protocol in any language.
import random
import time
# Simulated receiver
if received_frame == expected_sequence_number:
return "ACK"
else:
return "NAK"
else:
return None
# Simulated sender
13
sequence_number = 0
if acknowledgment == "ACK":
sequence_number += 1
else:
# Main function
def main():
sender(data_to_send, error_probability)
if __name__ == "__main__":
main()
14
Question 12: Implementation of Selective Repeat ARQ protocol in any language.
import random
import time
# Simulated receiver
if received_frame == expected_sequence_number:
return "ACK"
else:
15
# Frame received with an error or not received
return "NAK"
else:
return None
# Simulated sender
next_sequence_number = 0
if acknowledgment == "ACK":
else:
16
time.sleep(1) # Simulate a delay before resending
next_sequence_number += 1
# Main function
def main():
sender(data_to_send, error_probability)
if __name__ == "__main__":
main()
17