Computer - Networking - Saviour Final
Computer - Networking - Saviour Final
List of Experiment:
Sol->
#include <bits/stdc++.h>
// Initialize result
int n = b.length();
if (a[i] == b[i])
result += "0";
else
result += "1";
}
return result;
}
int n = dividend.length();
if (tmp[0] == '1')
else
// all-0s divisor.
+ dividend[pick];
pick += 1;
if (tmp[0] == '1')
else
return tmp;
}
string appended_data
<< "\n";
}
// checking if the message received by receiver is correct
// or not. If the remainder is all 0 then it is correct,
// else wrong.
string currxor
if (currxor.size() != key.size()) {
currxor.push_back(data[curr++]);
else {
currxor = mod2div(currxor, key);
if (currxor.size() == key.size()) {
if (currxor.find('1') != string::npos) {
else {
}
}
// Driver code
int main()
{
encodeData(data, key);
return 0;
}
// This code is contributed by MuskanKalra1 , Mayank Sharma
Output:
Sender side...
Remainder : 101
Receiver side...
Sol->
#include <bits/stdc++.h>
using namespace std;
// driver code
int main()
{
string str1 = "10110";
string str2 = "10101";
// function call
cout << "hamming dist is:"<<hammingDist(str1, str2);
return 0;
}
Soln->
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
string mainString;
cout << "Enter the main binary string: ";
cin >> mainString;
vector<string> binaryStrings(n);
cout << "Enter 4 binary strings of equal length:" << endl;
for (int i = 0; i < n; ++i) {
cin >> binaryStrings[i];
}
int minHammingDistance = INT_MAX;
cout << "The minimum Hamming distance among the 4 binary strings is: " <<
minHammingDistance << endl;
return 0;
}
Output(b):
4
Enter the main binary string: 10101
Enter 4 binary strings of equal length:
11101
11010
01011
10101
The minimum Hamming distance among the 4 binary strings is: 0
Note: Take appropriate user inputs, intermediate metrics; and show the output.
Soln->
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
int main() {
int rows, cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
// Create a matrix with an extra row and column for parity bits
vector<vector<int>> matrix(rows + 1, vector<int>(cols + 1, 0));
return 0;
}
Output:
Code:
WITH USER INPUT AND FRAME SIZE (If both sender and receiver given):
#include <bits/stdc++.h>
if (data[i] == '0')
data[i] = '1';
else
data[i] = '0';
return data;
int n = data.length();
if (n % block_size != 0) {
result += data[i];
}
for (int i = block_size; i < n; i += block_size) {
next_block += data[j];
+ (result[k] - '0');
carry = sum / 2;
if (sum == 0) {
sum = carry;
else if (sum == 1) {
sum = carry;
else if (sum == 2) {
sum = carry;
else {
sum = carry;
if (carry == 1) {
if (carry == 0) {
== 0) {
carry = 1;
else {
carry = 0;
result = final;
else {
result = additions;
return Ones_complement(result);
string rec_message,
int block_size)
string sender_checksum
= checkSum(sent_message, block_size);
if (count(receiver_checksum.begin(),
receiver_checksum.end(), '0')
== block_size) {
return true;
else {
return false;
int main()
string sent_message
= "101111011110";
string recv_message
= "101111011110";
int block_size = 3;
if (checker(sent_message,
recv_message,
block_size)) {
else {
return 0;
Output:
No Error
5. (a) Let us consider that we need to develop a routing technique in IPv4
system where user input will be dotted decimal value of IP address in classful
addressing scheme.
Code:
#include <iostream>
#include <sstream>
#include <vector>
vector<string> tokens;
string token;
istringstream tokenStream(str);
tokens.push_back(token);
return tokens;
uint32_t result = 0;
for (const string& octet : octets) {
return result;
int main() {
cout << "Enter the source IP address in dotted decimal format: ";
cout << "Enter the destination IP address in dotted decimal format: ";
return 0;
}
Output:
(b) Write a C program to identify the class of the IP address along with the
Code:
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
vector<string> tokens;
string token;
istringstream tokenStream(str);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
return tokens;
string ipClass;
string networkID;
ipClass = "A";
networkID = octets[0];
ipClass = "B";
ipClass = "C";
} else {
}
cout << "Class: " << ipClass << endl;
if (!networkID.empty()) {
int main() {
string ipAddress;
identifyClassAndNetworkID(ipAddress);
return 0;
Output:
Class: A
(c) Convert the dotted decimal into 32 bits IP address and check the class of
the IP
Code:
#include <iostream>
#include <sstream>
#include <bitset>
#include <vector>
vector<string> tokens;
string token;
istringstream tokenStream(str);
tokens.push_back(token);
return tokens;
uint32_t result = 0;
return result;
// Function to determine the class of the IP address based on the first byte
return 'A';
return 'C';
return 'D';
return 'E';
} else {
int main() {
string ipAddress;
bitset<32> ipAsBinary(ipAsUint);
cout << "IP Address in 32-bit binary format: " << ipAsBinary << endl;
if (ipClass != 'I') {
return 0;
Output:
Class: A
i) Write a C program to identify the first and last IP addresses of the network.
Code:
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
#include <cmath>
vector<string> tokens;
string token;
istringstream tokenStream(str);
tokens.push_back(token);
return tokens;
uint32_t result = 0;
return result;
int main() {
string input;
cout << "Enter the IP address in CIDR notation (e.g., 205.16.37.39/28): ";
cin >> input;
// Display results
return 0;
}
Output:
Code:
#include <iostream>
#include <sstream>
#include <vector>
#include <bitset>
#include <cmath>
vector<string> tokens;
string token;
istringstream tokenStream(str);
while (getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
return tokens;
uint32_t result = 0;
return result;
int main() {
string input;
cout << "Enter the IP address in CIDR notation (e.g., 205.16.37.39/28): ";
return 0;
Output:
205.16.37.33
205.16.37.34
205.16.37.35
205.16.37.36
205.16.37.37
205.16.37.38
205.16.37.39
205.16.37.40
205.16.37.41
205.16.37.42
205.16.37.43
205.16.37.44
205.16.37.45
205.16.37.46
(e) Let consider that if the user mentions the possible number of hosts
required
Let say, required number of host (n) = 45. Justify your answer!
Code:
#include <iostream>
}
bool isClassBSuitable(int hosts) {
int main() {
cin>>requiredHosts;
cout << "Required number of hosts: " << requiredHosts << endl;
if (isClassASuitable(requiredHosts)) {
} else {
if (isClassBSuitable(requiredHosts)) {
} else {
if (isClassCSuitable(requiredHosts)) {
} else {
cout << "Class C IP address is not suitable." << endl;
return 0;
Output: