MCPcopy Create free account
hub / github.com/TheAlgorithms/Java / xor

Method xor

src/main/java/com/thealgorithms/ciphers/XORCipher.java:48–54  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.

Callers 5

encryptMethod · 0.95
decryptMethod · 0.95
keyExpansionMethod · 0.45
addRoundKeyMethod · 0.45
encryptMethod · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected