xor method

Uint8List xor(
  1. Uint8List b
)

Implementation

Uint8List xor(Uint8List b) {
  if (lengthInBytes == 0 || b.lengthInBytes == 0) {
    throw ArgumentError.value(
        "lengthInBytes of Uint8List arguments must be > 0");
  }

  bool aIsBigger = lengthInBytes > b.lengthInBytes;
  int length = aIsBigger ? lengthInBytes : b.lengthInBytes;

  Uint8List buffer = Uint8List(length);

  for (int i = 0; i < length; i++) {
    var aa, bb;
    try {
      aa = elementAt(i);
    } catch (e) {
      aa = 0;
    }
    try {
      bb = b.elementAt(i);
    } catch (e) {
      bb = 0;
    }

    buffer[i] = aa ^ bb;
  }

  return buffer;
}