0

Possible Duplicate:
Simple XOR encryption routine in C/C++

Sorry, was double-post. Delete pls.

Community
  • 1
  • 1
Inkubus
  • 1
  • 1

2 Answers2

0

If filesize is the size of the buffer filebuffer than accessing filebuffer[filesize] is a mistake. This is what you do in the first iteration of the loop when i == filesize.
The last element of the buffer is filebuffer[filesize-1] and this is where your loop should start.

This error may potentially cause your code to crash but it may or may not be what's causing this to misbehave. Can you elaborate on what you see is "wrong" with the result?

shoosh
  • 76,898
  • 55
  • 205
  • 325
0

You didn't state what doesn't work, but I suspect the problem is an off-by one error. Instead of:

for ( i = filesize; i > 0; i-- )

you should do:

for ( i = filesize - 1; i >= 0; i-- )

(Array subscripts start at 0, not 1)

DarkDust
  • 90,870
  • 19
  • 190
  • 224