Here you can find the source of xorTwoByteArrays(byte[] byteArray1, byte[] byteArray2)
public static byte[] xorTwoByteArrays(byte[] byteArray1, byte[] byteArray2)
//package com.java2s; /*/*from w w w .j a va2 s . c om*/ * * jsse is Symmetric Searchable Encryption Library in Java * * jsse is developed by Sashank Dara (sashank.dara@gmail.com) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * **/ public class Main { public static byte[] xorTwoByteArrays(byte[] byteArray1, byte[] byteArray2) { int maxLength = byteArray1.length > byteArray2.length ? byteArray1.length : byteArray2.length; int minLength = byteArray1.length > byteArray2.length ? byteArray2.length : byteArray1.length; byte[] xorBytes = new byte[maxLength]; for (int i = 0; i < minLength; i++) { xorBytes[i] = (byte) (byteArray1[i] ^ byteArray2[i]); } if (maxLength == byteArray1.length) System.arraycopy(byteArray1, minLength, xorBytes, minLength, maxLength - minLength); if (maxLength == byteArray2.length) System.arraycopy(byteArray2, minLength, xorBytes, minLength, maxLength - minLength); return xorBytes; } }