xor two byte array - Android File Input Output

Android examples for File Input Output:Byte Array

Description

xor two byte array

Demo Code

/**//w ww .  java  2  s . c om
 * Source obtained from crypto-gwt. Apache 2 License.
 * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/
 * cryptogwt/util/ByteArrayUtils.java
 */
//package com.book2s;

public class Main {
    public static void xor(byte[] bytes, int offset, byte[] bytesToMix,
            int mixOffset, int len) {
        int bytesLength = offset + len;
        for (; offset < bytesLength; offset++) {
            bytes[offset] ^= bytesToMix[mixOffset++];
        }
    }

    public static void xor(byte[] dest, byte[] bytesToMix) {
        assert dest.length == bytesToMix.length : "different lengths: "
                + dest.length + " != " + bytesToMix.length;
        xor(dest, 0, bytesToMix, 0, dest.length);
    }
}

Related Tutorials