Java Array xor xorArrays(byte[] src, byte xor, byte xor_s, byte xor_e)

Here you can find the source of xorArrays(byte[] src, byte xor, byte xor_s, byte xor_e)

Description

xor ^ <0-127>

License

Apache License

Parameter

Parameter Description
src a parameter
xor key
xor_s key_1
xor_e key_2

Declaration

public final static byte xorArrays(byte[] src, byte xor, byte xor_s, byte xor_e) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2013 Zhang Zhuo(william@TinyGameX.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License./*from   w ww . j ava2  s .  c o m*/
 *******************************************************************************/

public class Main {
    /**
     * xor ^ <0-127>
     * 
     * @param src
     * @param xor
     *            key
     * @param xor_s
     *            key_1
     * @param xor_e
     *            key_2
     */
    public final static byte xorArrays(byte[] src, byte xor, byte xor_s, byte xor_e) {
        if (src == null || src.length == 0)
            return xor;
        if ((xor_s & 0xFF) == 0xFF && (xor_e & 0xFF) == 0xFF)
            return xor;// test
        else {
            int length = src.length;
            for (int i = 0; i < length; i++) {
                writeByte((src[i] & 0xFF) ^ xor, src, i);
                xor = (byte) (xor < xor_e ? xor + 1 : xor_s);
            }
            return xor;
        }
    }

    public final static int writeByte(int v, byte[] b, int off) {
        b[off] = (byte) v;
        return 1;
    }
}

Related

  1. xor(byte[] left, byte[] right)
  2. XorArray(byte[] pbSource, int nSourceOffset, byte[] pbBuffer, int nBufferOffset, int nLength)
  3. xorArrayBytes(byte[] operador1, byte[] operador2)
  4. xorArrays(byte[] a, byte[] b)
  5. xorArrays(byte[] a, byte[] b)
  6. xorBlock(byte[] a, int aOff, byte[] b, int bOff, byte[] dst, int dstOff, int len)
  7. xorByteArrays(byte[] a, byte[] b)
  8. xorByteArrays(byte[] first, byte[] second)
  9. xorBytes(byte[] data, byte[] key)