From 1c3e9f70b1640b3b2efa4e8c8b6cfbc2ba43986d Mon Sep 17 00:00:00 2001 From: Kshitij Date: Sun, 11 Aug 2024 21:55:12 +0530 Subject: [PATCH] Added recevier side checking for sent data. --- Codes/CRC.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/Codes/CRC.cpp b/Codes/CRC.cpp index 2e1a9d7..c8bb556 100644 --- a/Codes/CRC.cpp +++ b/Codes/CRC.cpp @@ -43,6 +43,35 @@ string encoder(string data, string key) { return data + crc; } +string performDivision(string data, string key) { + int keyLen = key.length(); + + // Initialize with the data to be divided + string temp = data.substr(0, keyLen); + + // Perform XOR operations on each segment + for (int i = keyLen; i < data.length(); i++) { + if (temp[0] == '1') { // Only perform XOR if the leading bit is 1 + temp = XOR(temp, key); + } + temp = temp.substr(1) + data[i]; // Shift left and add the next bit + } + + // Perform the final XOR operation + if (temp[0] == '1') { + temp = XOR(temp, key); + } + + // Extract the remainder (last keyLen-1 bits) + return temp.substr(temp.length() - (keyLen - 1)); +} + +// Function to check the correctness of received data +bool checkData(string data, string key) { + string remainder = performDivision(data, key); + return (remainder.find('1') == string::npos); // No '1' means remainder is all zeros +} + int main() { string data, key; @@ -51,13 +80,23 @@ int main() { cout << "Enter primary key:\t"; getline(cin, key); + cout<