Here you can find the source of xor(byte lhs[], byte rhs[])
public final static byte[] xor(byte lhs[], byte rhs[])
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w .ja v a2 s . c om * @return null if either arg is null or the args are not equal length */ public final static byte[] xor(byte lhs[], byte rhs[]) { if ((lhs == null) || (rhs == null) || (lhs.length != rhs.length)) return null; byte diff[] = new byte[lhs.length]; xor(lhs, 0, rhs, 0, diff, 0, lhs.length); return diff; } /** * xor the lhs with the rhs, storing the result in out. * * @param lhs one of the source arrays * @param startLeft starting index in the lhs array to begin the xor * @param rhs the other source array * @param startRight starting index in the rhs array to begin the xor * @param out output array * @param startOut starting index in the out array to store the result * @param len how many bytes into the various arrays to xor */ public final static void xor(byte lhs[], int startLeft, byte rhs[], int startRight, byte out[], int startOut, int len) { if ((lhs == null) || (rhs == null) || (out == null)) throw new NullPointerException("Null params to xor"); if (lhs.length < startLeft + len) throw new IllegalArgumentException("Left hand side is too short"); if (rhs.length < startRight + len) throw new IllegalArgumentException("Right hand side is too short"); if (out.length < startOut + len) throw new IllegalArgumentException("Result is too short"); for (int i = 0; i < len; i++) out[startOut + i] = (byte) (lhs[startLeft + i] ^ rhs[startRight + i]); } }