ComputerNetworksAndSecurity/Codes/CRC.cpp

37 lines
630 B
C++
Raw Normal View History

#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;
}