Key length requirement in a simple XOR implementation I don't have much previous experience at all with cryptography, this is pretty much the first time I've tried anything similar.

I'm trying to implement an extremely simple XOR encryption system in ComputerCraft for fun, here is the code:

local function xorEncrypt(data, key) 
    local klen = #key local 
    s = "" 
    for i = 1, #data do 
        s = s..string.char(bit.bxor(string.byte(data, i), string.byte(key, i % klen))) 
    end 
return s 
end


The only thing I need to know is, in this case, will the messages still be able to be decrypted if the key that I use is shorter than the data I am encrypting?
This cipher system is the original Vernam cipher.
(In the original Vernam cipher, the key was stored on a loop of paper tape that repeated over and over).

Like all practical encryption systems, the Vernam cipher has a secret key that it uses over and over.

ciphertext[i] = plaintext[i] bit_xor key[ i % keylength ]


This cipher can be seen as a variant of the Vigenère cipher, and has the same security.

Anyone with the secret key can decrypt a ciphertext message to recover bit-for-bit the original plaintext (no matter what the keylength is) with:

plaintext[i] = ciphertext[i] bit_xor key[ i % keylength ]



  Though the cipher is easy to understand and implement, for three
  centuries it resisted all attempts to break it; this earned it the
  description le chiffre indéchiffrable (French for 'the indecipherable
  cipher'). ...
  Kasiski entirely broke the cipher and published the technique ...
  In 1863 Friedrich Kasiski was the first to publish a
  successful general attack on the Vigenère cipher.


-- Wikipedia: Vigenère cipher

The people at the Cipher Exchange say the Vigenère cipher can be solved by pencil and paper methods with enough ciphertext -- ciphertext 15 times the length of the key.
The same techniques can be used to break this cipher, given the same amount of ciphertext.
(Some of those techniques are mentioned at "
What is the limit of plaintext required to break the Vigen&#232;re encryption?
").