xor function
Performs an XOR operation between two byte arrays aList
and bList
.
If an array is smaller, the missing bytes are considered 0. Returns um Uint8List as the result of XOR byte by byte.
Implementation
Uint8List xor(List<int> aList, List<int> bList) {
final a = Uint8List.fromList(aList);
final b = Uint8List.fromList(bList);
if (a.isEmpty || b.isEmpty) {
throw ArgumentError("Uint8List arguments must not be empty");
}
final length = a.length > b.length ? a.length : b.length;
final buffer = Uint8List(length);
for (int i = 0; i < length; i++) {
final aa = i < a.length ? a[i] : 0;
final bb = i < b.length ? b[i] : 0;
buffer[i] = aa ^ bb;
}
return buffer;
}