# The relationship between the key length and encrypt time in Xor algorithm?

I did work on the encryption algorithm and the decryption using the XOR method noticed that when more the key length, the less time spent on encryption and decryption.

I have two questions in particular:

1. Why the greater the key length less time?
2. in encryption algorithms using the XOR. Is the key should be a certain length or not?
-
Could you elaborate a bit what your "encryption algorithm using the XOR method" is exactly? For an one-time pad, the key length should be as much as the message length, so I suppose you are using something with repeated key? – Paŭlo Ebermann Apr 16 '14 at 20:37
Ok for example I use k1 has length 256 bit with message has 1024 bit then I divide message for four parts each part has 256 bit. then I encrypt each chunk by use key1. – MHS Apr 16 '14 at 20:57

## 1 Answer

For simple XOR-based encryption algorithms such as OTP, the key size must be the same as the message size. If you choose a smaller key and try to divide the message into chunks, you would not have a perfectly secure scheme anymore.

Now, since you tagged java, I'm assuming that this increase in time for smaller key sizes is due to the code trying to divide the message into chunks. In that case, this doesn't have much to do with the algorithm, but rather with how you are writing your code.

-
Since we're talking about implementation, it should be noted that XOR is embarrassingly parallel, if the message size merits it. – rath Apr 17 '14 at 13:35