diff options
Diffstat (limited to 'src/utils/xor_buf.cpp')
-rw-r--r-- | src/utils/xor_buf.cpp | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/utils/xor_buf.cpp b/src/utils/xor_buf.cpp index df4e62db9..779be81c3 100644 --- a/src/utils/xor_buf.cpp +++ b/src/utils/xor_buf.cpp @@ -16,11 +16,28 @@ u32bit xor_into_buf(byte buf[], u32bit buf_i, u32bit length, { const byte* in = static_cast<const byte*>(in_void); + byte last = 0; + byte count = 0; + for(u32bit i = 0; i != in_len; ++i) { - buf[buf_i] ^= in[i]; - buf_i = (buf_i + 1) % length; + if(in[i] != last) + { + buf[buf_i] ^= last; + buf_i = (buf_i + 1) % length; + + buf[buf_i] ^= count; + buf_i = (buf_i + 1) % length; + + last = in[i]; + count = 1; + } + else + ++count; } + + // final values of last, count are thrown away + return buf_i; } |