Easy way to generate XOR checksum in a stream?
1 answer
You can use LINQ to get the answer:
var checksum = memStream
.GetBuffer() // Get the underlying byte array
.Skip(1) // Skip the first byte
.Take(memStream.Length-3) // One for the beginning, two more for the end
.Aggregate(0, (p,v) => p ^ v); // XOR the accumulated value and the next byte
+4
source to share