Assuming you are encrypting meaningful human-readable text, it is possible to break this XOR cipher if the attacker will have:
- ciphertext encoded with key reuse (e.g. loop % sKey.size() )
- 2 ciphertexts encoded with the same key
Frequency analysis can break both cases.
But it is fine to xor plaintext with truly random key of the same length as message. It will be unbreakable cipher: One-Time Pad
OTP is immune even to brute-force attacks.Trying all keys simply yields all plaintexts, all equally likely to be the actual plaintext