Added XOR operation in CRC code.

TODO -> Add encoding function.
NEED TO FIX -> XOR operation only works when the length of data and key
is same.
This commit is contained in:
K 2024-07-29 19:27:12 +05:30
parent bc566b9a54
commit c1141bf596
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

36
Codes/CRC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <cstring>
using namespace std;
string XOR(string data, string key) {
// Dividend is data
// Divisor is the primary key, i.e. the key
string result = "";
int len = data.length();
// Performing XOR operation
for (int i=0; i<len; i++) {
if (data[i] == key[i]) {
result = result + "0";
}
else {
result = result + "1";
}
}
return result;
}
int main() {
string data, key;
cout<<endl<<"Enter data:\t";
getline(cin, data);
cout<<"Enter primary key:\t";
getline(cin, key);
cout<<XOR(data, key);
return 0;
}