Java xor xor(byte data[], byte key[])

Here you can find the source of xor(byte data[], byte key[])

Description

xor

License

Apache License

Declaration

public static byte[] xor(byte data[], byte key[]) 

Method Source Code

//package com.java2s;
/* ========================================================================
 * PlantUML : a free UML diagram generator
 * ========================================================================
 *
 * (C) Copyright 2009-2017, Arnaud Roques
 *
 * Project Info:  http://plantuml.com// w  ww  . j a  v  a  2  s  . co m
 * 
 * This file is part of PlantUML.
 *
 * 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.
 *
 *
 * Original Author:  Arnaud Roques
 */

public class Main {
    public static byte[] xor(byte data[], byte key[]) {
        final byte[] result = new byte[data.length];
        int pos = 0;
        for (int i = 0; i < result.length; i++) {
            result[i] = (byte) (data[i] ^ key[pos++]);
            if (pos == key.length) {
                pos = 0;
            }

        }
        return result;
    }
}

Related

  1. xOr(boolean x, boolean y)
  2. xor(boolean... bools)
  3. xor(boolean[] array)
  4. xor(boolean[][] b1, boolean[][] b2)
  5. xor(byte abyte0[])
  6. xor(byte lhs[], byte rhs[])
  7. xor(byte[] a, byte[] b)
  8. xor(byte[] a, byte[] b)
  9. xor(byte[] a, byte[] b)