Applies the XOR operation between the input bytes and the key bytes. If the key is shorter than the input, it wraps around (cyclically). @param inputBytes The input byte array (plaintext or ciphertext). @param keyBytes The key byte array used for XOR operation. @return A new byte array containing t
(final byte[] inputBytes, final byte[] keyBytes)
| 46 | * @return A new byte array containing the XOR result. |
| 47 | */ |
| 48 | public static byte[] xor(final byte[] inputBytes, final byte[] keyBytes) { |
| 49 | byte[] outputBytes = new byte[inputBytes.length]; |
| 50 | for (int i = 0; i < inputBytes.length; ++i) { |
| 51 | outputBytes[i] = (byte) (inputBytes[i] ^ keyBytes[i % keyBytes.length]); |
| 52 | } |
| 53 | return outputBytes; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Encrypts the given plaintext using the XOR cipher with the specified key. |
no outgoing calls
no test coverage detected