Hello so for an assignment I have to implement a simple hash for a file. The parameters are as followed:
- If the input length measured in the number of bytes is not a multiple of 4, add 0s to the end until it is a multiple of 4.
- Divide the input array into 4-byte blocks.
- Calculate the exclusive-or of all blocks as the hash output.
I have completed points a and b but I am stuck on c. I am unsure as where to go now. Here is my code so far:
public class HomeWork {
public static String file = "HW2P1input";
public static void main(String[] args) throws IOException {
Path path = Paths.get(file);
byte[] source = Files.readAllBytes(path);
byte newB[][] = divideArray(source,4);
}
public static byte[][] divideArray(byte[] source, int chunksize) {
byte[][] ret = new byte[(int)Math.ceil(source.length / (double)chunksize)][chunksize];
int start = 0;
for(int i = 0; i < ret.length; i++) {
if(start + chunksize > source.length) {
System.arraycopy(source, start, ret[i], 0, source.length - start);
} else {
System.arraycopy(source, start, ret[i], 0, chunksize);
}
start += chunksize ;
}
return ret;
}
}
I understand that ^ is the exclusive-or operator, however I do not understand how to use it when I only have one byte array.