Java Array xor xorend(byte[] in1, byte[] in2)

Here you can find the source of xorend(byte[] in1, byte[] in2)

Description

xorend

License

Open Source License

Declaration

private static byte[] xorend(byte[] in1, byte[] in2) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Sebastian Stenzel/* w w w .  j  av a 2s. co  m*/
 * This file is licensed under the terms of the MIT license.
 * See the LICENSE.txt file for more info.
 * 
 * Contributors:
 *     Sebastian Stenzel - initial API and implementation
 ******************************************************************************/

import java.util.Arrays;

public class Main {
    private static byte[] xorend(byte[] in1, byte[] in2) {
        if (in1 == null || in2 == null || in1.length < in2.length) {
            throw new IllegalArgumentException("Length of first input must be >= length of second input.");
        }

        final byte[] result = Arrays.copyOf(in1, in1.length);
        final int diff = in1.length - in2.length;
        for (int i = 0; i < in2.length; i++) {
            result[i + diff] = (byte) (result[i + diff] ^ in2[i]);
        }
        return result;
    }
}

Related

  1. xorByteArrays(byte[] a, byte[] b)
  2. xorByteArrays(byte[] first, byte[] second)
  3. xorBytes(byte[] data, byte[] key)
  4. xorData(final byte[] data, final byte[] passBytes)
  5. xorDecode(byte[] str, char[] key)
  6. xorI(long[] v, long[] o)
  7. xorTwoByteArrays(byte[] byteArray1, byte[] byteArray2)