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

Method xor

src/main/java/com/thealgorithms/ciphers/Blowfish.java:1121–1130  ·  view source on GitHub ↗

This method returns a string obtained by XOR-ing two strings of same length passed a method parameters @param String a and b are string objects which will be XORed and are to be of same length @return String object obtained by XOR operation on String a and String b

(String a, String b)

Source from the content-addressed store, hash-verified

1119 * @return String object obtained by XOR operation on String a and String b
1120 * */
1121 private String xor(String a, String b) {
1122 a = hexToBin(a);
1123 b = hexToBin(b);
1124 StringBuilder ans = new StringBuilder();
1125 for (int i = 0; i < a.length(); i++) {
1126 ans.append((char) (((a.charAt(i) - '0') ^ (b.charAt(i) - '0')) + '0'));
1127 }
1128 ans = new StringBuilder(binToHex(ans.toString()));
1129 return ans.toString();
1130 }
1131
1132 /**
1133 * This method returns addition of two hexadecimal numbers passed as parameters and moded with

Callers 5

fMethod · 0.95
keyGenerateMethod · 0.95
roundMethod · 0.95
encryptMethod · 0.95
decryptMethod · 0.95

Calls 5

hexToBinMethod · 0.95
binToHexMethod · 0.95
lengthMethod · 0.80
appendMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected