Java Utililty Methods xor

List of utility methods to do xor

Description

The list of methods to do xor are organized into topic(s).

Method

byte[]xor(byte[] first, byte[] second)
xor
if (first.length != second.length)
    throw new Exception("Arguments have different lengths");
byte[] output = new byte[first.length];
for (int i = 0; i < first.length; i++) {
    output[i] = (byte) (first[i] ^ second[i]);
return output;
voidxor(byte[] firstBytes, int firstOffset, byte[] secondBytes, int secondOffset, byte[] outBytes, int outOffset, int size)
xor
for (int i = 0; i < size; i++) {
    outBytes[outOffset + i] = (byte) (firstBytes[firstOffset + i] ^ secondBytes[secondOffset + i]);
byte[]xor(byte[] op1, byte[] op2)
Bitwise XOR between corresponding bytes
byte[] result;
if (op2.length > op1.length) {
    result = new byte[op1.length];
} else {
    result = new byte[op2.length];
for (int i = 0; i < result.length; i++) {
    result[i] = (byte) (op1[i] ^ op2[i]);
...
byte[]xor(byte[] source, byte[] key)
Returns a new array with the xor of source with key.
int srcLen = source.length;
int keyLen = key.length;
byte[] ret = new byte[srcLen];
for (int i = 0; i < srcLen; i++) {
    int keyIndex = i % keyLen;
    ret[i] = (byte) (source[i] ^ key[keyIndex]);
return ret;
...
voidxor(byte[] x, byte[] y)
xor
int i = 0;
do {
    x[i] ^= y[i];
    ++i;
    x[i] ^= y[i];
    ++i;
    x[i] ^= y[i];
    ++i;
...
byte[]xor(byte[]... bytesArr)
xor
if (bytesArr == null) {
    return null;
byte[] data = null;
for (int i = 0; i < bytesArr.length; i++) {
    byte[] bytes = bytesArr[i];
    if (bytes == null) {
        continue;
...
char[]xor(char[] a, char[] b)
xor
int length = Math.min(a.length, b.length);
char[] result = new char[length];
for (int i = 0; i < length; i++) {
    result[i] = (char) (a[i] ^ b[i]);
return result;
booleanxor(double lhs, double rhs)
Check if exactly one of the two given values is not zero.
return (lhs != 0 ^ rhs != 0);
booleanxor(final boolean value1, final boolean value2)
Implementation of exclusive OR (XOR), meaning 1 and only 1 value can be true.
return ((value1 || value2) && !(value1 && value2));
booleanxor(final boolean x, final boolean y)
Boolean xor operation.
return x != y;