Java xor xor(byte[]... bytesArr)

Here you can find the source of xor(byte[]... bytesArr)

Description

xor

License

Apache License

Declaration

public static byte[] xor(byte[]... bytesArr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static byte[] xor(byte[]... bytesArr) {
        if (bytesArr == null) {
            return null;
        }//from www .ja  v  a 2 s . c o  m

        byte[] data = null;
        for (int i = 0; i < bytesArr.length; i++) {
            byte[] bytes = bytesArr[i];
            if (bytes == null) {
                continue;

            } else if (data == null) {
                data = new byte[bytes.length];
                System.arraycopy(bytes, 0, data, 0, data.length);
                continue;
            }

            if (bytes.length != data.length) {
                throw new IllegalArgumentException("Different length of two byte arrays");
            }

            for (int j = 0; j < data.length; j++) {
                data[j] ^= bytes[j];
            }
        }

        return data;
    }

    public static byte[] xor(byte[] bytes, byte aByte) {
        if (bytes == null) {
            return null;
        }

        byte[] data = new byte[bytes.length];
        System.arraycopy(bytes, 0, data, 0, data.length);
        for (int i = 0; i < data.length; i++) {
            data[i] ^= aByte;
        }

        return data;
    }
}

Related

  1. xor(byte[] first, byte[] second)
  2. xor(byte[] firstBytes, int firstOffset, byte[] secondBytes, int secondOffset, byte[] outBytes, int outOffset, int size)
  3. xor(byte[] op1, byte[] op2)
  4. xor(byte[] source, byte[] key)
  5. xor(byte[] x, byte[] y)
  6. xor(char[] a, char[] b)
  7. xor(double lhs, double rhs)
  8. xor(final boolean value1, final boolean value2)
  9. xor(final boolean x, final boolean y)