What does this function do?

  • Thread starter Thread starter Anil Gupte
  • Start date Start date
A

Anil Gupte

I am trying to learn C++ and one sample written by someone for me contains
this:

void DecryptStream(BYTE* buf, ULONG size)
{
for (ULONG i=0; i<size; i++)
{
buf ^= 1;
}
}

Can some one tell me what this is doing? Especially ^ - is that an XOR?

Thanx,
 
Anil Gupte said:
I am trying to learn C++ and one sample written by someone for me contains
this:

void DecryptStream(BYTE* buf, ULONG size)
{
for (ULONG i=0; i<size; i++)
{
buf ^= 1;
}
}

Can some one tell me what this is doing? Especially ^ - is that an XOR?


Yes, ^ is the C/C++ XOR operator, so the function 'decrypt' the stream of
bytes (but can be used to 'crypt' the data too).

Regards
 
Anil Gupte said:
I am trying to learn C++ and one sample written by someone for me contains
this:

void DecryptStream(BYTE* buf, ULONG size)
{
for (ULONG i=0; i<size; i++)
{
buf ^= 1;
}
}

Can some one tell me what this is doing? Especially ^ - is that an XOR?


As Cholo already told you, yes that's XOR.

It flips the least significant bit of each of <size> bytes starting at
 
Thanx for the info! Ben and Cholo.

--
Anil Gupte
www.keeninc.net
www.icinema.com

Ben Voigt said:
Anil Gupte said:
I am trying to learn C++ and one sample written by someone for me contains
this:

void DecryptStream(BYTE* buf, ULONG size)
{
for (ULONG i=0; i<size; i++)
{
buf ^= 1;
}
}

Can some one tell me what this is doing? Especially ^ - is that an XOR?


As Cholo already told you, yes that's XOR.

It flips the least significant bit of each of <size> bytes starting at
 
Back
Top