Java xor xor(byte[] array1, byte[] array2)

Here you can find the source of xor(byte[] array1, byte[] array2)

Description

XORs two byte arrays of different or same size.

License

Open Source License

Parameter

Parameter Description
array1 The first array to XOR
array2 The second array to XOR

Return

The resulting byte array

Declaration

protected static byte[] xor(byte[] array1, byte[] array2) 

Method Source Code

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

public class Main {
    /**/*  ww  w .  jav a  2  s .c  o  m*/
     * XORs two byte arrays of different or same size.
     * @param array1 The first array to XOR
     * @param array2 The second array to XOR
     * @return The resulting byte array
     */
    protected static byte[] xor(byte[] array1, byte[] array2) {
        if (array1.length > array2.length) { // make array2 the larger array
            byte[] tmp = array2;
            array2 = array1;
            array1 = tmp;
        }
        for (int i = 0; i < array1.length; i++) {
            array2[i] = (byte) (array1[i] ^ array2[i]);
        }
        return array2;
    }
}

Related

  1. xor(byte[] a, byte[] b)
  2. xor(byte[] a, byte[] b)
  3. xor(byte[] a, byte[] b)
  4. xor(byte[] a, int offsetA, byte[] b, int offsetB, byte[] dst, int dstOffset, int length)
  5. xor(byte[] aBuffer, int aOffset, int aLength, byte[] aMask, int aMaskOffset)
  6. XOR(byte[] array1, byte[] array2)
  7. xor(byte[] b1, byte[] b2)
  8. xor(byte[] b1, byte[] b2)
  9. xor(byte[] block, byte[] val)