Here you can find the source of xor(byte[] source, byte[] key)
Parameter | Description |
---|---|
source | a parameter |
key | a parameter |
public static byte[] xor(byte[] source, byte[] key)
//package com.java2s; public class Main { /**/*w ww. j av a2s .c o m*/ * Returns a new array with the xor of source with key. * If key is shorter than source, then it is reused. * * @param source * @param key * @return */ public static byte[] xor(byte[] source, byte[] 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; } }