For which key length (as a function of file size) is a XOR cipher considered as safe?

It is well-known that, doing a XOR of a file against a short key is highly insecure encryption (can be broken with frequency analysis).

But if the length of the key is equal to (or has same order of magnitude than) the length of the file to be encrypted, then the situation is close to a one-time-pad / Vernam cipher and it is secure (no frequency analysis can be done).

Is there a rule of thumb for which XOR cipher is generally considered as safe?

e.g.:

• `key size = file size` => super safe, one-time pad
• `key size = (1/2) file size` => looks really really safe, I don't see how a freq analysis could work with only 4 repetitions

• `key size = (1/100) file size` => ?

• `key size = (1/10000) file size` => ?

Let's say the file is 10 GB if it helps to get the order of magnitudes.

Example with `key size = (1/2) file size`:

``````file:       0101 0111    (size 8)
key:        0100 0100    (0100, i.e. size 4, repeated twice)

cyphertext: 0001 0011
``````

Here the key `0100` is repeated twice. How could someone having only the size-8 cyphertext and knowledge of the fact the key is of size 4 break it?

• to answer the bold question: they wouldn't, unless some of the text was known. If you know that a key repeats exactly once, and you know part of the file contents (EXIF, headers, BOM, etc), you can tell exactly what's on the other part of the CT keyed by the same offset. Contextually expanding those areas allows crawling beyond the duplicated materials. You can also use file format analysis to eliminate options, like a missing reserved char in a run of binary data. – dandavis Oct 17 '17 at 4:35
• to answer the title's question, the percentage is 100%. – dandavis Oct 17 '17 at 4:48

• So even with `keylength = filesize / 2`, you claim that it can be broken? If so could you provide an example with filesize = 10? (would help a lot for getting the idea!) – Basj Oct 16 '17 at 19:30