So, I am creating a LorenzSZ40 simulator. And I'm still in early stage of creating it. The thing is the fact that I am using byte[]
arrays in order to store plain text and key data.
For example I have this
byte[] plainText = {1, 0, 1, 0, 0};
and
byte[] key = {1, 1, 1, 0, 1};
When XOR'ing that, the result should be 0, 1, 0, 0, 1
But the problem is that I cannot use ^
operator on byte[]
.
public static byte[] xor(byte[] plainText, byte[] key) {
byte[] result = new byte[Math.min(plainText.length, key.length)];
for (int i = 0 ; i < result.length ; i++) {
result[i] = (byte) (((int) plainText[i]) ^ ((int) key[i]));
}
return result;
}
public static void main(String[] args) {
String pt = "10100";
String key = "11011";
byte[] som = pt.getBytes();
byte[] k = key.getBytes();
//0, 1, 1, 1, 1
String nm = new String(xor(som, k));
System.out.println(xor(som, k));
}
This is the code I have tried. When I run it I only get [B@3d494fbf
and if I was to use
String nm = new String(xor(pci, key));
System.out.println(new String(nm));
Instead of
String nm = new String(xor(som, k));
System.out.println(xor(som, k));
I wouldn't get anything at all.
My question is, how should I make it right?