Connecting Tech Pros Worldwide Forums | Help | Site Map

What does this function do?

Anil Gupte
Guest
 
Posts: n/a
#1: Dec 18 '07
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[i] ^= 1;
}
}

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

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



Cholo Lennon
Guest
 
Posts: n/a
#2: Dec 18 '07

re: What does this function do?


"Anil Gupte" <anil-list@icinema.comwrote in message
news:ObtdotVQIHA.4880@TK2MSFTNGP03.phx.gbl...
Quote:
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[i] ^= 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


--
Cholo Lennon
Bs.As.
ARG


Ben Voigt [C++ MVP]
Guest
 
Posts: n/a
#3: Dec 18 '07

re: What does this function do?



"Anil Gupte" <anil-list@icinema.comwrote in message
news:ObtdotVQIHA.4880@TK2MSFTNGP03.phx.gbl...
Quote:
>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[i] ^= 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 <sizebytes starting at
<buf>, which should not be called "decryption".
Quote:
>
Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com
>

Anil Gupte
Guest
 
Posts: n/a
#4: Dec 19 '07

re: What does this function do?


Thanx for the info! Ben and Cholo.

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

"Ben Voigt [C++ MVP]" <rbv@nospam.nospamwrote in message
news:OiiemBcQIHA.5692@TK2MSFTNGP04.phx.gbl...
Quote:
>
"Anil Gupte" <anil-list@icinema.comwrote in message
news:ObtdotVQIHA.4880@TK2MSFTNGP03.phx.gbl...
Quote:
>>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[i] ^= 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 <sizebytes starting at
<buf>, which should not be called "decryption".
>
Quote:
>>
>Thanx,
>--
>Anil Gupte
>www.keeninc.net
>www.icinema.com
>>
>
>

Closed Thread