#include <bits/stdc++.h>
//#include <conio.h>
int main( )
{
int i,j,k,l;
//Get Frame
int fs;
cout << "\n Enter Frame size: " ;
cin >> fs;
int f[ 20 ] ;
cout << "\n Enter Frame:" ;
for ( i= 0 ; i< fs; i++ )
{
cin >> f[ i] ;
}
//Get Generator
int gs;
cout << "\n Enter Generator size: " ;
cin >> gs;
int g[ 20 ] ;
cout << "\n Enter Generator:" ;
for ( i= 0 ; i< gs; i++ )
{
cin >> g[ i] ;
}
cout << "\n Sender Side:" ;
cout << "\n Frame: " ;
for ( i= 0 ; i< fs; i++ )
{
cout << f[ i] ;
}
cout << "\n Generator :" ;
for ( i= 0 ; i< gs; i++ )
{
cout << g[ i] ;
}
//Append 0's
int rs= gs- 1 ;
cout << "\n Number of 0's to be appended: " << rs;
for ( i= fs; i< fs+ rs; i++ )
{
f[ i] = 0 ;
}
int temp[ 20 ] ;
for ( i= 0 ; i< 20 ; i++ )
{
temp[ i] = f[ i] ;
}
cout << "\n Message after appending 0's :" ;
for ( i= 0 ; i< fs+ rs; i++ )
{
cout << temp[ i] ;
}
//Division
for ( i= 0 ; i< fs; i++ )
{
j= 0 ;
k= i;
//check whether it is divisible or not
if ( temp[ k] >= g[ j] )
{
for ( j= 0 ,k= i; j< gs; j++ ,k++ )
{
if ( ( temp[ k] == 1 && g[ j] == 1 ) || ( temp[ k] == 0 && g[ j] == 0 ) )
{
temp[ k] = 0 ;
}
else
{
temp[ k] = 1 ;
}
}
}
}
//CRC
int crc[ 15 ] ;
for ( i= 0 ,j= fs; i< rs; i++ ,j++ )
{
crc[ i] = temp[ j] ;
}
cout << "\n CRC bits: " ;
for ( i= 0 ; i< rs; i++ )
{
cout << crc[ i] ;
}
cout << "\n Transmitted Frame: " ;
int tf[ 15 ] ;
for ( i= 0 ; i< fs; i++ )
{
tf[ i] = f[ i] ;
}
for ( i= fs,j= 0 ; i< fs+ rs; i++ ,j++ )
{
tf[ i] = crc[ j] ;
}
for ( i= 0 ; i< fs+ rs; i++ )
{
cout << tf[ i] ;
}
cout << "\n Receiver side : " ;
cout << "\n Received Frame: " ;
for ( i= 0 ; i< fs+ rs; i++ )
{
cout << tf[ i] ;
}
for ( i= 0 ; i< fs+ rs; i++ )
{
temp[ i] = tf[ i] ;
}
//Division
for ( i= 0 ; i< fs+ rs; i++ )
{
j= 0 ;
k= i;
if ( temp[ k] >= g[ j] )
{
for ( j= 0 ,k= i; j< gs; j++ ,k++ )
{
if ( ( temp[ k] == 1 && g[ j] == 1 ) || ( temp[ k] == 0 && g[ j] == 0 ) )
{
temp[ k] = 0 ;
}
else
{
temp[ k] = 1 ;
}
}
}
}
cout << "\n Reaminder: " ;
int rrem[ 15 ] ;
for ( i= fs,j= 0 ; i< fs+ rs; i++ ,j++ )
{
rrem[ j] = temp[ i] ;
}
for ( i= 0 ; i< rs; i++ )
{
cout << rrem[ i] ;
}
int flag= 0 ;
for ( i= 0 ; i< rs; i++ )
{
if ( rrem[ i] ! = 0 )
{
flag= 1 ;
}
}
if ( flag== 0 )
{
cout << "\n Since Remainder Is 0 Hence Message Transmitted From Sender To Receriver Is Correct" ;
}
else
{
cout << "\n Since Remainder Is Not 0 Hence Message Transmitted From Sender To Receriver Contains Error" ;
}
// getch();
return 0 ;
}
/* OUTPUT
Enter Frame size: 6
Enter Frame:1
0
0
1
0
0
Enter Generator size: 4
Enter Generator:1
1
0
1
Sender Side:
Frame: 100100
Generator :1101
Number of 0's to be appended: 3
Message after appending 0's :100100000
CRC bits: 001
Transmitted Frame: 100100001
Receiver side :
Received Frame: 100100001
Reaminder: 000
Since Remainder Is 0 Hence Message Transmitted From Sender To Receriver Is Corr
ect
*/
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vI2luY2x1ZGUgPGNvbmlvLmg+CiAKaW50IG1haW4oKQp7CiAgICBpbnQgaSxqLGssbDsKICAgICAKICAgIC8vR2V0IEZyYW1lCiAgICBpbnQgZnM7CiAgICBjb3V0PDwiXG4gRW50ZXIgRnJhbWUgc2l6ZTogI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ogCiAgICAvL0RpdmlzaW9uCiAgICBmb3IoaT0wO2k8ZnM7aSsrKQogICAgewogICAgICAgIGo9MDsKICAgICAgICBrPWk7CiAgICAgICAgLy9jaGVjayB3aGV0aGVyIGl0IGlzIGRpdmlzaWJsZSBvciBub3QKICAgICAgICBpZiAodGVtcFtrXT49Z1tqXSkKICAgICAgICB7CiAgICAgICAgICAgIGZvcihqPTAsaz1pO2o8Z3M7aisrLGsrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoKHRlbXBba109PTEgJiYgZ1tqXT09MSkgfHwgKHRlbXBba109PTAgJiYgZ1tqXT09MCkpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdGVtcFtrXT0wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHRlbXBba109MTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KIAogICAgLy9DUkMKICAgIGludCBjcmNbMTVdOwogICAgZm9yKGk9MCxqPWZzO2k8cnM7aSsrLGorKykKICAgIHsKICAgICAgICBjcmNbaV09dGVtcFtqXTsKICAgIH0KIAogICAgY291dDw8IlxuIENSQyBiaXRzOiAiOwogICAgZm9yKGk9MDtpPHJzO2krKykKICAgIHsKICAgICAgICBjb3V0PDxjcmNbaV07CiAgICB9CiAKICAgIGNvdXQ8PCJcbiBUcmFuc21pdHRlZCBGcmFtZTogIjsKICAgIGludCB0ZlsxNV07CiAgICBmb3IoaT0wO2k8ZnM7aSsrKQogICAgewogICAgICAgIHRmW2ldPWZbaV07CiAgICB9CiAgICBmb3IoaT1mcyxqPTA7aTxmcytycztpKyssaisrKQogICAgewogICAgICAgIHRmW2ldPWNyY1tqXTsKICAgIH0KICAgIGZvcihpPTA7aTxmcytycztpKyspCiAgICB7CiAgICAgICAgY291dDw8dGZbaV07CiAgICB9CiAKICAgIGNvdXQ8PCJcbiBSZWNlaXZlciBzaWRlIDogIjsKICAgIGNvdXQ8PCJcbiBSZWNlaXZlZCBGcmFtZTogIjsKICAgIGZvcihpPTA7aTxmcytycztpKyspCiAgICB7CiAgICAgICAgY291dDw8dGZbaV07CiAgICB9CiAKICAgIGZvcihpPTA7aTxmcytycztpKyspCiAgICB7CiAgICAgICAgdGVtcFtpXT10ZltpXTsKICAgIH0KIAogICAgLy9EaXZpc2lvbgogICAgZm9yKGk9MDtpPGZzK3JzO2krKykKICAgIHsKICAgICAgICBqPTA7CiAgICAgICAgaz1pOwogICAgICAgIGlmICh0ZW1wW2tdPj1nW2pdKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGo9MCxrPWk7ajxncztqKyssaysrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZigodGVtcFtrXT09MSAmJiBnW2pdPT0xKSB8fCAodGVtcFtrXT09MCAmJiBnW2pdPT0wKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICB0ZW1wW2tdPTA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgdGVtcFtrXT0xOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogCiAgICBjb3V0PDwiXG4gUmVhbWluZGVyOiAiOwogICAgaW50IHJyZW1bMTVdOwogICAgZm9yIChpPWZzLGo9MDtpPGZzK3JzO2krKyxqKyspCiAgICB7CiAgICAgICAgcnJlbVtqXT0gdGVtcFtpXTsKICAgIH0KICAgIGZvcihpPTA7aTxycztpKyspCiAgICB7CiAgICAgICAgY291dDw8cnJlbVtpXTsKICAgIH0KIAogICAgaW50IGZsYWc9MDsKICAgIGZvcihpPTA7aTxycztpKyspCiAgICB7CiAgICAgICAgaWYocnJlbVtpXSE9MCkKICAgICAgICB7CiAgICAgICAgICAgIGZsYWc9MTsKICAgICAgICB9CiAgICB9CiAKICAgIGlmKGZsYWc9PTApCiAgICB7CiAgICAgICAgY291dDw8IlxuIFNpbmNlIFJlbWFpbmRlciBJcyAwIEhlbmNlIE1lc3NhZ2UgVHJhbnNtaXR0ZWQgRnJvbSBTZW5kZXIgVG8gUmVjZXJpdmVyIElzIENvcnJlY3QiOwogICAgfQogICAgZWxzZQogICAgewogICAgICAgIGNvdXQ8PCJcbiBTaW5jZSBSZW1haW5kZXIgSXMgTm90IDAgSGVuY2UgTWVzc2FnZSBUcmFuc21pdHRlZCBGcm9tIFNlbmRlciBUbyBSZWNlcml2ZXIgQ29udGFpbnMgRXJyb3IiOwogICAgfQogICAvLyBnZXRjaCgpOwogICByZXR1cm4gMDsKfQogCi8qIE9VVFBVVAogCiAKIEVudGVyIEZyYW1lIHNpemU6IDYKIAogRW50ZXIgRnJhbWU6MQowCjAKMQowCjAKIAogRW50ZXIgR2VuZXJhdG9yIHNpemU6IDQKIAogRW50ZXIgR2VuZXJhdG9yOjEKMQowCjEKIAogU2VuZGVyIFNpZGU6CiBGcmFtZTogMTAwMTAwCiBHZW5lcmF0b3IgOjExMDEKIE51bWJlciBvZiAwJ3MgdG8gYmUgYXBwZW5kZWQ6IDMKIE1lc3NhZ2UgYWZ0ZXIgYXBwZW5kaW5nIDAncyA6MTAwMTAwMDAwCiBDUkMgYml0czogMDAxCiBUcmFuc21pdHRlZCBGcmFtZTogMTAwMTAwMDAxCiBSZWNlaXZlciBzaWRlIDoKIFJlY2VpdmVkIEZyYW1lOiAxMDAxMDAwMDEKIFJlYW1pbmRlcjogMDAwCiBTaW5jZSBSZW1haW5kZXIgSXMgMCBIZW5jZSBNZXNzYWdlIFRyYW5zbWl0dGVkIEZyb20gU2VuZGVyIFRvIFJlY2VyaXZlciBJcyBDb3JyCmVjdAogCiov
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:10:5: error: ‘cout’ was not declared in this scope
cout<<"\n Enter Frame size: ";
^~~~
prog.cpp:10:5: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:75:0,
from prog.cpp:1:
/usr/include/c++/6/iostream:61:18: note: ‘std::cout’
extern ostream cout; /// Linked to standard output
^~~~
prog.cpp:11:5: error: ‘cin’ was not declared in this scope
cin>>fs;
^~~
prog.cpp:11:5: note: suggested alternative:
In file included from /usr/include/x86_64-linux-gnu/c++/6/bits/stdc++.h:75:0,
from prog.cpp:1:
/usr/include/c++/6/iostream:60:18: note: ‘std::cin’
extern istream cin; /// Linked to standard input
^~~
stdout