I am trying to compute the crc checksum of two binary strings but I can only get the first iteration of the loop. Converting a string to a string array and then finally an int array. Error checking is done elsewhere.
public String checksum(String a, String b) {
// These arrays will convert the input strings to an array
String[] mArray = a.split("");
String[] pArray = b.split("");
// Creates arrays from the above corresponding arrays
int[] mAr = new int[mArray.length];
int[] pAr = new int[pArray.length];
// populates message array
for (int i = 0; i < a.length(); i++) {
mAr[i] = Integer.parseInt(mArray[i]);
}
// populates pattern array
for (int i = 0; i < b.length(); i++) {
pAr[i] = Integer.parseInt(pArray[i]);
}
//int frame = mAr.length - pAr.length + 1;
int pLength = pAr.length;
int mLength = mAr.length;
// int[] checksum = new int[frame];
System.out.println(pLength);
//CHECKSUM ITERATION
for (int i = 0; i < pAr.length; i++) {
mAr[i] = mAr[i] ^ pAr[i];
if (i ==pLength) {
// mAr[i] = mAr[i] >> 1;
i = 0;
}
}
for (int i = 0; i < mAr.length; i++) {
System.out.print(mAr[i]);
}
My test is Message: 11001010 Pattern: 10011 Expected output: 0100 But instead, I get: 01010010 Which is the first xor of the two strings. But the loop won't continue to xor that string with pattern again. What can I do to correct this loop issue? Or am I going about this incorrectly?