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:
parent
bc566b9a54
commit
c1141bf596
36
Codes/CRC.cpp
Normal file
36
Codes/CRC.cpp
Normal 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;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user