Compare commits

..

3 Commits

Author SHA1 Message Date
b94dba6141
Added encoder function
Fixed XOR operator
TODO - Add boilerplate from syllabus file, then merge with main branch
2024-07-29 19:57:00 +05:30
c1141bf596
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.
2024-07-29 19:27:12 +05:30
bc566b9a54
Added description in README. 2024-07-29 19:25:08 +05:30
2 changed files with 68 additions and 0 deletions

63
Codes/CRC.cpp Normal file
View File

@ -0,0 +1,63 @@
#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 dataLen = data.length();
int keyLen = key.length();
// Perform XOR operation
for (int i=0; i<keyLen; i++) {
if (i < dataLen) {
// Only perform XOR if within the length of data
if (data[i] == key[i]) {
result += '0';
}
else {
result += '1';
}
} else {
// If data length exceeded, append the key
result += key[i];
}
}
return result;
}
string encoder(string data, string key) {
int keyLen = key.length();
// Append n-1 zeroes to the data
string dataWithZeroes = data + string(keyLen-1, '0');
// Perform XOR operation with the key
string remainder = XOR(dataWithZeroes, key);
// Get the remainder (last n-1 bits)
string crc = remainder.substr(remainder.length() - (keyLen-1));
// Append the CRC to the original data
return data + crc;
}
int main() {
string data, key;
cout << endl << "Enter data:\t";
getline(cin, data);
cout << "Enter primary key:\t";
getline(cin, key);
string messageToSend = encoder(data, key);
cout<<endl<<"--------------------"<<endl;
cout<<"Message to be sent:\t"<<messageToSend;
cout<<endl<<"--------------------"<<endl;
return 0;
}
// TODO:
// - Check if input data is actually binary

View File

@ -0,0 +1,5 @@
# Computer Networks and Security
This Git repository is a comprehensive resource for the Computer Networks and Security (CNS) course under the SPPU 2019 syllabus. It includes materials on fundamental concepts such as network architectures, protocols, and technologies, as well as practical implementations of client-server applications and insights into the data link layer and routing protocols. The repository also covers the application layer's role and essential network security topics, providing students with the knowledge and skills needed to master the course outcomes effectively.
---