Java xor xor(byte[] a, byte[] b)

Here you can find the source of xor(byte[] a, byte[] b)

Description

XOR's two byte arrays.

License

Open Source License

Parameter

Parameter Description
a the first array of bytes.
b the second array of bytes.

Return

an array of bytes after being XORed.

Declaration

public static byte[] xor(byte[] a, byte[] b) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**// w  ww  .  j  a v a  2 s  .c o m
     * XOR's two byte arrays.
     *
     * @param a the first array of bytes.
     * @param b the second array of bytes.
     * @return an array of bytes after being XORed.
     */
    public static byte[] xor(byte[] a, byte[] b) {
        int length = Math.max(a.length, b.length);
        byte[] result = new byte[length];

        int i = 0;
        for (byte val : a) {
            result[i] = (byte) (val ^ b[i++]);
        }

        return result;
    }
}

Related

  1. xor(byte data[], byte key[])
  2. xor(byte lhs[], byte rhs[])
  3. xor(byte[] a, byte[] b)
  4. xor(byte[] a, byte[] b)
  5. xor(byte[] a, byte[] b)
  6. xor(byte[] a, byte[] b)
  7. xor(byte[] a, byte[] b)
  8. xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)
  9. xor(byte[] aBuffer, int aOffset, int aLength, byte[] aMask, int aMaskOffset)