1D Parity #include // Function to calculate parity bit int calculate_parity(int data[], int size, int parity_type) {     int count = 0;     for (int i = 0; i < size; i++) {         if (data[i] == 1)             count++;     }         // Even Parity: Add 0 if count is even, else add 1     // Odd Parity: Add 1 if count is even, else add 0     if (parity_type == 0)         return (count % 2 == 0) ? 0 : 1; // Even parity     else         return (count % 2 == 0) ? 1 : 0; // Odd parity } // Function to check received data for errors int check_parity(int data[], int size, int parity_bit, int parity_type) {     int count = 0;     for (int i = 0; i < size; i++) {         if (data[i] == 1)             count++;     }         // Include the parity bit     count += parity_bit;     // Check if the parity is maintained     if ((parity_type == 0 && count % 2 == 0) || (parity_type == 1 && count % 2 == 1))         return 1;  // No error     else         return 0;  // Error detected } int main() {     int size, parity_type;         printf("Enter the number of data bits: ");     scanf("%d", &size);         int data[size];     printf("Enter the data bits (0s and 1s):\n");     for (int i = 0; i < size; i++) {         scanf("%d", &data[i]);     }         printf("Choose Parity Type (0 for Even, 1 for Odd): ");     scanf("%d", &parity_type);         // Calculate the parity bit     int parity_bit = calculate_parity(data, size, parity_type);         // Append parity bit to data     printf("\nTransmitted Data: ");     for (int i = 0; i < size; i++) {         printf("%d ", data[i]);     }     printf("%d (Parity Bit)\n", parity_bit);     // Simulating received data     int received_data[size + 1];     printf("\nEnter received data bits (including parity bit):\n");     for (int i = 0; i < size + 1; i++) {         scanf("%d", &received_data[i]);     }         // Check for errors     int error_check = check_parity(received_data, size, received_data[size], parity_type);         if (error_check)         printf("No error detected in received data.\n");     else         printf("Error detected in received data!\n");         return 0; } 2D Parity #include #include #define MAX 10  // Maximum matrix size int main() {     int i, j, row, column, count;     int array[MAX + 1][MAX + 1]; // Increased size to accommodate parity bits     printf("Enter number of rows (max %d): ", MAX);     scanf("%d", &row);     printf("Enter number of columns (max %d): ", MAX);     scanf("%d", &column);     if (row > MAX || column > MAX) {         printf("Error: Maximum size exceeded!\n");         return EXIT_FAILURE;     }     // Input binary data     printf("Enter the bit stream (%dx%d):\n", row, column);     for (j = 0; j < row; j++) {         for (i = 0; i < column; i++) {             scanf("%d", &array[j][i]);             if (array[j][i] != 0 && array[j][i] != 1) {                 printf("Invalid input! Enter only 0 or 1.\n");                 return EXIT_FAILURE;             }         }     }     // Display Initial Bit Stream     printf("\nInitial bit stream:\n");     for (j = 0; j < row; j++) {         for (i = 0; i < column; i++) {             printf("%d ", array[j][i]);         }         printf("\n");     }     // Compute Row Parity     for (j = 0; j < row; j++) {         count = 0;         for (i = 0; i < column; i++) {             if (array[j][i] == 1) {                 count++;             }         }         array[j][column] = (count % 2 == 0) ? 0 : 1; // Add row parity bit     }     // Compute Column Parity     for (i = 0; i <= column; i++) { // Includes the new parity column         count = 0;         for (j = 0; j < row; j++) {             if (array[j][i] == 1) {                 count++;             }         }         array[row][i] = (count % 2 == 0) ? 0 : 1; // Add column parity bit     }     // Display Output Bit Stream with Parity Bits     printf("\nOutput bit stream with parity bits:\n");     for (j = 0; j <= row; j++) {         for (i = 0; i <= column; i++) {             printf("%d ", array[j][i]);         }         printf("\n");     }     return EXIT_SUCCESS; } ERROR DECTION USING CRC #include #include #include #define MAX_DATA_LEN 64 #define MAX_POLY_LEN 50 char data[MAX_DATA_LEN], rem[MAX_POLY_LEN]; char gen_poly[MAX_POLY_LEN] = ""; // Predefined polynomials char poly8[] = "110000111";          // CRC-8 Polynomial char poly10[] = "11000110101";       // CRC-10 Polynomial char poly16[] = "10001000000100001"; // CRC-16 Polynomial char poly32[] = "100000100110000010001110110110111"; // CRC-32 Polynomial int data_len, ch; // Function to choose the CRC Generating Polynomial void chooseGeneratingPolynomial() {     printf("\nPress 1 for CRC-8");     printf("\nPress 2 for CRC-10");     printf("\nPress 3 for CRC-16");     printf("\nPress 4 for CRC-32\nChoice: ");     scanf("%d", &ch);     switch (ch) {         case 1: strcpy(gen_poly, poly8); break;         case 2: strcpy(gen_poly, poly10); break;         case 3: strcpy(gen_poly, poly16); break;         case 4: strcpy(gen_poly, poly32); break;         default: printf("Invalid choice\n"); exit(1);     }     printf("\nGenerating polynomial is %s\n", gen_poly); } // XOR Operation for Division void xorOperation(int start) {     for (int c = 0; c < strlen(gen_poly); c++) {         rem[start + c] = (rem[start + c] == gen_poly[c]) ? '0' : '1';     } } // Compute Remainder (CRC Calculation) void remCal() {     int poly_len = strlen(gen_poly);     int e = 0;     // Initialize remainder with the first poly_len bits of data     for (int i = 0; i < poly_len; i++) {         rem[i] = data[i];     }     e = poly_len;     // Perform division     while (e <= data_len + poly_len - 1) {         if (rem[0] == '1') {             xorOperation(0);         }         // Shift remainder left by 1 bit         for (int c = 0; c < poly_len - 1; c++) {             rem[c] = rem[c + 1];         }         // Bring down the next bit from data         rem[poly_len - 1] = data[e++];     }     // Null-terminate the remainder     rem[poly_len - 1] = '\0'; } // Sender Function void sender() {     data_len = strlen(data);     // Append zero bits (equal to polynomial length - 1)     for (int i = data_len; i < data_len + strlen(gen_poly) - 1; i++) {         data[i] = '0';     }     data[data_len + strlen(gen_poly) - 1] = '\0';     printf("\nModified data is %s", data);     remCal();     printf("\nRemainder is %s", rem);     // Append remainder to the original data     for (int i = data_len; i < data_len + strlen(gen_poly) - 1; i++) {         data[i] = rem[i - data_len];     }     printf("\nFinal codeword being transmitted is %s", data); } // Error Checking Function void checkError() {     remCal();     int error_detected = 0;     for (int i = 0; i < strlen(gen_poly) - 1; i++) {         if (rem[i] == '1') {             error_detected = 1;             break;         }     }     if (error_detected) {         printf("\nError detected, data processing aborted!!\n\n");     } else {         printf("\nNo error detected, proceed to data processing\n\n");     } } // Receiver Function void receiver() {     printf("\nCode received!!\nPress 0 to detect error");     printf("\nPress 1 to introduce errors: ");     scanf("%d", &ch);     if (ch == 0) {         checkError();     } else if (ch == 1) {         int error_pos;         do {             printf("\nEnter the position where error is to be inserted (1 to %d): ", data_len + strlen(gen_poly) - 1);             scanf("%d", &error_pos);         } while (error_pos < 1 || error_pos > data_len + strlen(gen_poly) - 1);         // Introduce error by flipping the bit         data[error_pos - 1] = (data[error_pos - 1] == '0') ? '1' : '0';         printf("\nData after introducing error: %s\n", data);         checkError();     } else {         printf("\nInvalid option\n");     } } // Main Function int main() {     printf("Enter data size (max %d bits): ", MAX_DATA_LEN - strlen(gen_poly) + 1);     int data_size;     scanf("%d", &data_size);     if (data_size <= 0 || data_size > MAX_DATA_LEN - strlen(gen_poly) + 1) {         printf("Invalid data size\n");         return 1;     }     printf("\nEnter the %d-bit data: ", data_size);     scanf("%s", data);     chooseGeneratingPolynomial();     sender();     receiver();     return 0; } DISTANCE ROUTING #include #include int findShortestPath(int G[6][6], int Vertices, int Edges, int edge[20][2], int Source) {     int i, j, u, v, k, distance[20], parent[20], flag = 1;     for (i = 0; i < Vertices; i++) {         distance[i] = 999;         parent[i] = -1;     }     distance[Source - 1] = 0;     for (i = 0; i < Vertices - 1; i++) {         for (k = 0; k < Edges; k++) {             u = edge[k][0];             v = edge[k][1];             if (distance[u] + G[u][v] < distance[v]) {                 distance[v] = distance[u] + G[u][v];                 parent[v] = u;             }         }     }     for (k = 0; k < Edges; k++) {         u = edge[k][0];         v = edge[k][1];         if (distance[u] + G[u][v] < distance[v]) {             flag = 0;         }     }     printf("Destination\tCost\tPath\n");     if (flag) {         for (i = 0; i < Vertices; i++) {             int nodes[10], b = 9, next;             nodes[b--] = i;             next = parent[i];             nodes[b--] = next;             while (next != -1) {                 next = parent[next];                 nodes[b--] = next;             }             if (distance[i] == 999) {                 printf("\n%d\t\t%d\t", i, nodes[-1]);             } else {                 printf("\n%d\t\t%d\t", i, distance[i]);                 for (int h = 10; h > 0; h--) {                     if (nodes[h] == -1) {                         for (int g = h + 1; g < 10; g++) {                             if (g == 9)                                 printf("%d", nodes[g]);                             else                                 printf("%d-->", nodes[g]);                         }                         break;                     }                 }                 printf("\n");             }         }     }     return flag; } int main() {     int Vertices = 6, edge[20][2];     int i, j, k = 0;     int graph[6][6] = {         {0, 1, 15, 0, 0, 0},         {1, 0, 3, 4, 0, 0},         {5, 3, 0, 5, 9, 0},         {0, 4, 5, 0, 2, 6},         {0, 0, 9, 2, 0, 3},         {0, 0, 0, 6, 3, 0}     };     printf("The Adjacency Matrix representation of graph\n");     for (i = 0; i < Vertices; i++) {         for (j = 0; j < Vertices; j++) {             printf("%d\t", graph[i][j]);             if (graph[i][j] != 0) {                 edge[k][0] = i;                 edge[k++][1] = j;             }         }         printf("\n");     }     for (int i = 0; i < Vertices; i++) {         printf("\n----------------------------\n\tSource vertex %d\n", i);         findShortestPath(graph, Vertices, k, edge, i + 1);     }     return 0; } ARQS PROToCALLS #include #include void StopAndWait(); void GoBackN(); void Selective(); int main(int argc, char* argv[]) {     int val;     while (1) {         printf("\nEnter:\n1. Stop-And-Wait protocol\n2. Go-Back-N\n3. Selective Repeat\n4. Exit\n");         scanf("%d", &val);         switch (val) {             case 1:                 StopAndWait();                 break;             case 2:                 GoBackN();                 break;             case 3:                 Selective();                 break;             default:                 return 0;         }     }     return EXIT_SUCCESS; } // **Stop-And-Wait Protocol** void StopAndWait() {     int n, i = 0, frame;     printf("\nEnter the total number of frames: ");     scanf("%d", &n);     while (i < n) {         printf("\nEnter received frame: ");         scanf("%d", &frame);         if (frame == i + 1) {             printf("Transmitting.... ACK to frame %d\n", frame);             i++;         } else {             printf("Negative ACK.... to frame %d\n", i + 1);         }     } } // **Go-Back-N Protocol** void GoBackN() {     int n, i = 0, frame, size, t;     printf("\nEnter the total number of frames: ");     scanf("%d", &n);     printf("Enter window size of frames: ");     scanf("%d", &size);     printf("Sending frames\n");     for (int j = 0; j < size; j++) {         printf("%d ", j + 1);     }     for (int j = 0; j < n; j++) {         printf("\nFrame %d is received (1 for success, 0 for failure): ", j + 1);         scanf("%d", &t);         if (t == 1) {             printf("Sending ACK to frame %d\nSliding window\n", j + 1);             printf("\nIn window: ");             for (int k = j + 1; k < j + 1 + size; k++) {                 if (k < n) printf("%d ", k + 1);             }         } else {             printf("\nRetransmitting frames\t");             for (int m = j; m < j + size; m++) {                 if (m < n) printf("%d ", m + 1);             }             j--;  // Go back to retransmit         }     } } // **Selective Repeat Protocol** void Selective() {     int n, i = 0, frame, m, size;     printf("\nEnter the total number of frames: ");     scanf("%d", &n);     printf("Sending frames\n");     for (int j = 0; j < n; j++) {         printf("%d ", j + 1);     }     printf("\nEnter the number of frames received: ");     scanf("%d", &m);         int a[n];     printf("\nEnter received frames: \n");     for (int i = 0; i < m; i++) {         scanf("%d", &a[i]);     }     int trigger = 0;     for (int i = 0; i < n; i++) {         trigger = 0;         for (int j = 0; j < m; j++) {             if ((i + 1) == a[j]) {                 trigger = 1;             }         }         if (trigger == 0) {             printf("\nRetransmitting frame %d\n", i + 1);             a[m++] = i + 1;         }     }     // Sorting the frames     for (int i = 0; i < n; i++) {         for (int j = 0; j < n; j++) {             if (a[i] < a[j]) {                 int temp = a[i];                 a[i] = a[j];                 a[j] = temp;             }         }     }     printf("\nSorted frames: ");     for (int i = 0; i < n; i++) {         printf("%d ", a[i]);     } } DLL TCP SOCKET CHATROOM SERVER: import time import socket import sys print('Setting up Server...') time.sleep(1) # Get the hostname, IP Address from socket and set Port soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) host_name = socket.gethostname() ip = socket.gethostbyname(host_name) port = 12345  # Changed port to a safer one (above 1024) soc.bind((host_name, port)) print(f"Server running on {host_name} ({ip}), Port: {port}") # Get server admin name name = input('Enter your name: ') # Listening for incoming connections soc.listen(1) print("Waiting for incoming connections...") # Accept connection connection, addr = soc.accept() print(f"Received connection from {addr[0]} ({addr[1]})\n") print(f"Connection Established. Connected From: {addr[0]} ({addr[1]})") # Get a connection from the client side client_name = connection.recv(1024).decode('utf-8') print(f"{client_name} has connected.") print("Type '[bye]' to leave the chat room.") connection.send(name.encode('utf-8')) while True:     message = input("Me => ")         if message.lower() == '[bye]':         message = "Bye, leaving the chat room!"         connection.send(message.encode('utf-8'))         print("\nDisconnected from chat.")         break         connection.send(message.encode('utf-8'))         # Receiving message     message = connection.recv(1024).decode('utf-8')     if message.lower() == '[bye]':         print(f"\n{client_name} has left the chat room.")         break         print(f"{client_name} => {message}") # Close the connection connection.close() soc.close() CLIENT: import time import socket import sys print('Starting Client...') time.sleep(1) # Get client machine details client_host = socket.gethostname() client_ip = socket.gethostbyname(client_host) print(f"Client Running on {client_host} ({client_ip})") # Get information to connect to the server server_host = input("Enter Server's IP Address: ") name = input("Enter your name: ") port = 12345  # Changed to a safer port above 1024 print(f"Trying to connect to the server: {server_host}, Port: {port}") time.sleep(1) # Connect to the server soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) soc.connect((server_host, port)) print("Connected...\n") # Send client name soc.send(name.encode('utf-8')) # Receive server name server_name = soc.recv(1024).decode('utf-8') print(f"{server_name} has joined the chat.") print("Type '[bye]' to exit the chat.") while True:     # Receiving message     message = soc.recv(1024).decode('utf-8')     if message.lower() == '[bye]':         print(f"\n{server_name} has left the chat room.")         break     print(f"{server_name} => {message}")     # Sending message     message = input("Me => ")     if message.lower() == '[bye]':         soc.send(message.encode('utf-8'))         print("\nDisconnected from chat.")         break     soc.send(message.encode('utf-8')) # Close the connection soc.close() SOCKET PROGRAMMING 1 [client-server] Server: import socket HOST = '127.0.0.1'  # The server's hostname or IP address PORT = 65432        # Port used by the server # Create a socket object with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:     s.bind((HOST, PORT))     s.listen()     print("Server is listening on", HOST, ":", PORT)     conn, addr = s.accept()     with conn:         print('Connected by', addr)         while True:             data = conn.recv(1024)             if not data:                 break             conn.sendall(data)  # Echo back the received data Client: import socket HOST = '127.0.0.1'  # The server's hostname or IP address PORT = 65432        # Port used by the server # Create a socket object with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:     s.connect((HOST, PORT))     s.sendall(b"Hello, world")  # Send a message to the server     data = s.recv(1024)  # Receive response from server print('Received:', repr(data))  # Print the response from the server CRC - 8 BIT CRC for 8 bits #include #include #define MAX_DATA_LEN 64 #define POLY "110000111" // CRC-8 Polynomial char data[MAX_DATA_LEN], rem[9]; // Remainder should match polynomial length // XOR Operation for Division void xorOperation(int start) { for (int c = 0; c < 8; c++) { rem[start + c] = (rem[start + c] == POLY[c]) ? '0' : '1'; } } // Compute Remainder (CRC Calculation) void computeCRC() { int data_len = strlen(data); int poly_len = strlen(POLY); // Initialize remainder with first poly_len bits for (int i = 0; i < poly_len; i++) { rem[i] = data[i]; } int e = poly_len; while (e <= data_len + poly_len - 1) { if (rem[0] == '1') { xorOperation(0); } // Shift remainder left by 1 bit for (int c = 0; c < poly_len - 1; c++) { rem[c] = rem[c + 1]; } // Bring down next bit from data rem[poly_len - 1] = (e < data_len + poly_len - 1) ? data[e] : '0'; e++; } rem[poly_len - 1] = '\0'; // Null-terminate } // Sender Function void sender() { int data_len = strlen(data); // Append zero bits (poly_len - 1) for (int i = data_len; i < data_len + 7; i++) { data[i] = '0'; } data[data_len + 7] = '\0'; printf("\nModified data: %s", data); computeCRC(); printf("\nCRC-8 Remainder: %s", rem); // Append remainder to data for (int i = data_len; i < data_len + 7; i++) { data[i] = rem[i - data_len]; } printf("\nFinal codeword: %s\n", data); } // Error Checking Function void checkError() { computeCRC(); for (int i = 0; i < 7; i++) { if (rem[i] == '1') { printf("\nError detected!\n"); return; } } printf("\nNo error detected.\n"); } // Receiver Function void receiver() { printf("\nReceived codeword: %s", data); printf("\nPress 0 to check error or 1 to introduce error: "); int ch; scanf("%d", &ch); if (ch == 1) { int error_pos; printf("\nEnter bit position to flip (1 to %ld): ", strlen(data)); scanf("%d", &error_pos); if (error_pos < 1 || error_pos > strlen(data)) { printf("Invalid position\n"); return; } data[error_pos - 1] = (data[error_pos - 1] == '0') ? '1' : '0'; printf("\nData after introducing error: %s\n", data); } checkError(); } // Main Function int main() { printf("Enter binary data (max %d bits): ", MAX_DATA_LEN - 8); scanf("%s", data); sender(); receiver(); return 0; } _________________________________________________________________________________________________________________ NEIGHBOURHOOD TABLE #include #include #include #include int i,j,n; int x[15],y[15]; float distance [15][15]; void createNetwork(){ int x_range,y_range; printf("Enter the number of nodes(max 15):"); scanf("%d",&n); printf("Enter the X-Coordinates ranges:"); scanf("%d",&x_range); printf("Enter the Y-Coordinates ranges:"); scanf("%d",&y_range); srand(time(NULL)); for(i=0;i=distance[i][j]) printf("%d:( %.2f )\t",j+1,distance[i][j]); } } } int main(int argc, char** argv) { createNetwork(); computeDistance(); findNeighbor(); return (EXIT_SUCCESS); }