473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

What does this function do?

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
Dec 18 '07 #1
3 1025
"Anil Gupte" <an*******@icinema.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
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
Dec 18 '07 #2

"Anil Gupte" <an*******@icinema.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
>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".
>
Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com

Dec 18 '07 #3
Thanx for the info! Ben and Cholo.

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

"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:Oi**************@TK2MSFTNGP04.phx.gbl...
>
"Anil Gupte" <an*******@icinema.comwrote in message
news:Ob**************@TK2MSFTNGP03.phx.gbl...
>>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".
>>
Thanx,
--
Anil Gupte
www.keeninc.net
www.icinema.com


Dec 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
37
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture...
7
by: Jonathan Fine | last post by:
Giudo has suggested adding optional static typing to Python. (I hope suggested is the correct word.) http://www.artima.com/weblogs/viewpost.jsp?thread=85551 An example of the syntax he proposes...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
21
by: Helge Jensen | last post by:
I've got some data that has Set structure, that is membership, insert and delete is fast (O(1), hashing). I can't find a System.Collections interface that matches the operations naturally offered...
4
by: grizggg | last post by:
I have searched and not found an answer to this question. I ran upon the following statement in a *.cpp file in a member function: static const char * const pacz_HTMLContentTypeHeader =...
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.