Java xor xor(byte[] data, byte[] xork)

Here you can find the source of xor(byte[] data, byte[] xork)

Description

Xors two byte arrays.

License

Open Source License

Parameter

Parameter Description
data First array.
xork Second array

Return

Result of xoring the two arrays.

Declaration

public static byte[] xor(byte[] data, byte[] xork) 

Method Source Code

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

public class Main {
    /**/*from   w  w  w .ja  v a  2s  . c  o m*/
     * Xors two byte arrays.
     * 
     * @param data First array.
     * @param xork Second array
     * @return Result of xoring the two arrays.
     */
    public static byte[] xor(byte[] data, byte[] xork) {
        byte[] ret = new byte[data.length];

        int block_size = xork.length;
        int block_number = data.length / block_size;
        int rest = data.length % block_size;

        for (int i = 0; i < block_number; i++)
            for (int j = 0; j < block_size; j++)
                ret[i * block_size + j] = (byte) (data[i * block_size + j] ^ xork[j]);

        for (int j = 0; j < rest; j++)
            ret[block_number * block_size + j] = (byte) (data[block_number
                    * block_size + j] ^ xork[j]);

        return ret;
    }
}

Related

  1. xor(byte[] b1, byte[] b2)
  2. xor(byte[] block, byte[] val)
  3. xor(byte[] block, byte[] val)
  4. xor(byte[] bytes, int offset, byte[] bytesToMix, int mixOffset, int len)
  5. xor(byte[] bytes1, byte[] bytes2)
  6. xor(byte[] first, byte[] second)
  7. xor(byte[] firstBytes, int firstOffset, byte[] secondBytes, int secondOffset, byte[] outBytes, int outOffset, int size)
  8. xor(byte[] op1, byte[] op2)
  9. xor(byte[] source, byte[] key)