Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- void show_array(int a[], int n){
- for(int i = 0; i < n; i++){
- cout << a[i] << " ";
- }
- cout << endl;
- }
- void division(int temp[], int gen[], int n, int r){
- for(int i = 0; i < n; i++){
- if(gen[0] == temp[i]){
- for(int j = 0, k = i; j < r + 1; j++, k++){
- if(!(temp[k] ^ gen[j]))
- temp[k] = 0;
- else
- temp[k] = 1;
- }
- }
- }
- }
- int main(){
- int n;
- cout << "Enter the size of data: " << endl;
- cin >> n;
- int dataword[20];
- int temp[20];
- cout << "Enter the data: " << endl;
- for(int i = 0; i < n; i++){
- cin >> dataword[i];
- temp[i] = dataword[i];
- }
- int generator[20];
- cout << "Enter the generator: " << endl;
- for(int i = 0; i < n; i++){
- cin >> generator[i];
- }
- cout << "Enter the size of codeword: " << endl;
- int code_size;
- cin >> code_size;
- for(int i = n; i < code_size; i++){
- temp[i] = 0;
- }
- cout << "Sender side: " << endl;
- cout << "The given dataword is: " << endl;
- show_array(dataword, n);
- cout << "The codeword is: " << endl;
- show_array(temp, code_size);
- division(temp, generator, n, (code_size - n));
- cout << "Syndrome is: " << endl;
- for(int i = n; i < code_size; i++){
- cout << temp[i] << " ";
- }
- cout << endl;
- int codeword[code_size];
- for(int i = 0; i < n; i++){
- codeword[i] = dataword[i];
- }
- for(int i = n; i < code_size; i++){
- codeword[i] = temp[i];
- }
- cout << "The codeword transmitted is: " << endl;
- show_array(codeword, code_size);
- cout << "\nReciever side: " << endl;
- cout << "Enter the codeword recieved: " << endl;
- int message[code_size];
- for(int i = 0; i < code_size; i++){
- cin >> message[i];
- temp[i] = message[i];
- }
- division(temp, generator, n, code_size - n);
- for(int i = n; i < code_size; i++){
- if(temp[i]){
- cout << "Error detected in message" << endl;
- return 0;
- }
- }
- cout << "No error detected in message" << endl;
- cout << "Recieved message is: " << endl;
- for(int i = 0; i < n; i++){
- cout << message[i] << " ";
- }
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement