0

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?

Nothing Nothing
  • 126
  • 1
  • 8
  • you need to print the result array as suggested by @ resueman ,if you want to see output of your xor function otherwise println will just print the reference hashcode – Pavneet_Singh Sep 07 '16 at 12:58
  • @resueman @Pavneet Singh Indeed, `Arrays.toString()` solved part of the problem. But now the output is `0, 0, 0, 0, 0` instead of `0, 1, 1, 1, 1` – Nothing Nothing Sep 07 '16 at 12:58
  • print your som array and go though your logic with that output ,you will see the problem plus now the question is not a duplicate and i can't answer because it marked as duplicate, you can use the hint – Pavneet_Singh Sep 07 '16 at 13:15
  • i have flagged your question to open again, hopefully will be opened soon – Pavneet_Singh Sep 07 '16 at 13:23
  • you need to edit your question focusing on output or post new question.happy coding – Pavneet_Singh Sep 07 '16 at 16:17
  • It wasn't a problem with output anyway. Just me doing `xor(som, som)` not typing in the key anyway – Nothing Nothing Sep 07 '16 at 17:05
  • yeah but initially your problem was output that confused the @resueman and moderator to understand that there was a flaw in you logic too, anyway good you have done it – Pavneet_Singh Sep 08 '16 at 08:57

0 Answers0