def xorHexStrings hexString1 String hexString2 String val iterator1 he

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def xorHexStrings(hexString1: String, hexString2: String) = {
val iterator1 = hexString1.sliding(2, 2)
val iterator2 = hexString2.sliding(2, 2)
val result = new StringBuilder
if (hexString2.length > hexString1.length) {
while (iterator1.hasNext) {
val i = Integer.toString(Integer.parseInt(iterator1.next(), 16) ^
Integer.parseInt(iterator2.next(), 16), 16)
if (i.length == 1) result.append("0")
result.append(i)
}
while (iterator2.hasNext) result.append(iterator2.next())
} else {
while (iterator2.hasNext) {
val i = Integer.toString(Integer.parseInt(iterator1.next(), 16) ^
Integer.parseInt(iterator2.next(), 16), 16)
if (i.length == 1) result.append("0")
result.append(i)
}
while (iterator1.hasNext) result.append(iterator1.next())
}
result.toString()
}