0% found this document useful (0 votes)
28 views

Algorithms

The document describes 7 experiments related to networking concepts: 1. CRC checksum generation and error detection 2. Bit stuffing and destuffing to encode and decode data frames 3. Go Back N sliding window protocol simulation 4. Selective repeat ARQ algorithm for reliable packet transmission 5. Distance vector routing using Bellman-Ford algorithm 6. Stop-and-wait protocol for reliable data transmission 7. Encryption/decryption of strings using character substitution cipher

Uploaded by

Srikumar T B
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Algorithms

The document describes 7 experiments related to networking concepts: 1. CRC checksum generation and error detection 2. Bit stuffing and destuffing to encode and decode data frames 3. Go Back N sliding window protocol simulation 4. Selective repeat ARQ algorithm for reliable packet transmission 5. Distance vector routing using Bellman-Ford algorithm 6. Stop-and-wait protocol for reliable data transmission 7. Encryption/decryption of strings using character substitution cipher

Uploaded by

Srikumar T B
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment 1: Cyclic Redundancy Check (CRC)

1. Take the input message (in binary) and copy it to an output message
buffer.
2. If the CRC mode is enabled, append zeroes to the output message buffer
such that its length is equal to the length of the generator polynomial.
3. Perform XOR operation between the output message buffer and the
generator polynomial.
4. Iterate over each bit of the input message and perform the following
steps:
 If the current bit of the output message buffer is 1, perform another XOR
operation between the output message buffer and the generator
polynomial shifted left by the number of bits already processed.
 If the current bit of the output message buffer is 0, simply skip to the
next bit.
5. Check for errors by looking for any 1's in the output message buffer. If
there are any, return 0 to indicate that an error occurred during
transmission.
6. If there are no errors, return 1 to indicate successful transmission.
Experiment 2: Bit Stuffing and Destuffing
1. Take the input data (in binary) and count the number of consecutive 1's.
2. Append the current bit to the output buffer and increment the output
buffer index.
3. If the count of consecutive 1's reaches 5 and the next bit is also 1,
append a 0 to the output buffer to stuff the bit and reset the count of
consecutive 1's to 0.
4. Repeat steps 2-3 for all bits in the input data.
5. Prepend and append the stuffed data with a special flag sequence of
"01111110" to indicate the start and end of the data frame.
6. To destuff the data, scan through the stuffed data and remove any "0"
that immediately follows 5 consecutive 1's.
7. Return the destuffed data.
Experiment 3: Sliding Window Go Back N :
1. Set winsize to 8 and initialize temp1, temp2, temp3, temp4, and i to 0.
2. Generate a random integer value for noframes.
3. While moreframes is greater than or equal to 0, do the following: a.
Simulate the sliding window protocol by calling the simulate function
with winsize as the argument. Set the value returned by simulate to
temp1. b. Update temp4 by adding the value of temp1. c. For each
frame from temp3 + 1 to temp4, print "Sending frame X", where X is the
frame number. d. Call the receiver function with temp1 as the argument.
Set the value returned by receiver to temp2. e. Update temp3 by adding
the value of temp2. f. Print "Acknowledgement for the frames up to X",
where X is the value of temp3. g. Subtract temp2 from moreframes. h.
Set temp4 to temp3. i. If winsize is less than or equal to 0, set winsize to
8.
4. Print "End of sliding window protocol" and exit the program.
The simulate function:
1. Generate a random integer value for temp1.
2. If temp1 is equal to 0, repeat step 1 until temp1 is not equal to 0.
3. Return temp1 modulo winsize.
The receiver function:
1. Generate a random integer value for i.
2. Return 1.
Experiment 4: Selective Repeat Algorithm
1. Prompt the user to enter the number of packets to be sent.
2. Initialize an array of frames, where each frame contains a data field and
an acknowledgment field (initialized to 'y').
3. Send the packets to the receiver.
4. Randomly select a packet to simulate a lost packet, and mark its
acknowledgment field as 'n'.
5. Check each frame's acknowledgment field, and for any frames with an
'n' acknowledgment, resend the packet and wait for acknowledgment.
6. When an acknowledgment for a packet is received, mark its
acknowledgment field as 'y'.
7. Repeat steps 5-6 until all packets have been acknowledged.
8. Print a message indicating that all packets have been sent successfully.
Experiment 5: Distance Vector Routing algorithm using the Bellman-Ford
algorithm.
1. User inputs the number of nodes in the network, and the cost of each
route between nodes.
2. The algorithm initializes the "via" array to indicate that each node is
reached directly from itself.
3. For each pair of nodes that are directly connected, the algorithm
initializes the distance array to 1 to indicate a direct connection.
4. The Bellman-Ford algorithm is applied to find the shortest path between
each pair of nodes. For each node pair (i,j), the algorithm checks
whether going through a third node (k) results in a shorter path than the
current best path. If it does, then the path through k is updated as the
best path.
5. The algorithm outputs the cost of each route and the intermediate
nodes (via which the route passes) to reach each node in the network.

Experiment 6: Stop and Wait Protocol


1. User inputs the number of frames to be sent, the contents of each
frame, and the time when the first frame will be ready.
2. The sender() function sends the frames one at a time and waits for
acknowledgement from the receiver.
3. The recv() function receives the frames and sends an acknowledgement
back to the sender.
4. The program uses a sliding window protocol to ensure reliable data
transmission and handles possible errors.
5. The program outputs the time at which each frame is sent, arrives at the
receiver, and is acknowledged. It also outputs any relevant error
messages.
Experiment 7: Encryption and Decryption Algorithm
1. User is presented with a menu of options: input a string, encrypt string,
decrypt string, or exit.
2. If the user selects "input a string," they are prompted to enter a string to
encrypt and an integer to use as the encryption key.
3. If the user selects "encrypt string," the program encrypts the string using
the key by subtracting the key value from each character in the string.
4. If the user selects "decrypt string," the program decrypts the string using
the key by adding the key value to each character in the string.
5. If the user selects "exit," the program exits.
6. If the user inputs an invalid option, the program prints "Invalid choice."
and prompts the user to input another choice.
7. The program continues to run until the user selects "exit."

You might also like