2
This is a simple checksum. The math behind is this: gen(data) = -sum(data) mod 256 Since (a + b) mod c = ((a mod c) + (b mod c)) mod c the intermediate sums can already be reduced modulo 256. Casting to a byte implicitly performs modulo 256, and so does += between two bytes. Finally (byte)(0 ...