#include <iostream>
using namespace std;

void calculateCRC(string data, string divisor) {
    int dataLength = data.length();
    int divisorLength = divisor.length();

    // Append zeros to the data (same as the length of the divisor - 1)
    string dividend = data;
    for (int i = 1; i < divisorLength; i++) {
        dividend += "0";
    }

    // Perform division using XOR
    for (int i = 0; i <= dividend.length() - divisorLength; i++) {
        if (dividend[i] == '1') {
            for (int j = 0; j < divisorLength; j++) {
                dividend[i + j] = (dividend[i + j] == divisor[j]) ? '0' : '1';
            }
        }
    }

    // Extract the remainder (last divisorLength-1 bits)
    string crc = dividend.substr(dataLength, divisorLength - 1);

    // Append CRC to the original data
    string transmittedData = data + crc;

    // Output
    cout << "Original Data: " << data << endl;
    cout << "CRC: " << crc << endl;
    cout << "Transmitted Data: " << transmittedData << endl;
}

int main() {
    string data, divisor;

    cout << "Enter the binary data: ";
    cin >> data;

    cout << "Enter the binary divisor: ";
    cin >> divisor;

    calculateCRC(data, divisor);

    return 0;
}
