# What's happening here?

In the following snippet, the text is being "encrypted" or something along those lines.  I was hoping someone could tell me exactly what's being done....

char szTest[]={
'T'            ^ ( char) 0x0FF,
'E'            ^ ( char) 0x0FF,
'S'            ^ ( char) 0x0FF,
'T'            ^ ( char) 0x0FF,
}

Tony
LVL 1
###### Who is Participating?

Commented:
That is doing a one's complement of the character value. For example:

'T' = 0101100 (in binary)

'T' ^ (char) 0x0FF => 0101100 ^ 11111111 = 1010011
0

Commented:
Bit-wise Exclusive Or (XOR) (^) has the following properties:
1 ^ 1 = 0
1 ^ 0 = 1
0 ^ 1 = 1
0 ^ 0 = 0

so that a byte XOR'd with FF (all 1s), basically creates a "negative image"
of the byte - all the 0s become 1s and all all the 1s become 0s.

0

Commented:
^ is the bitwise XOR operation

your T , E , S, T etc ate xor'ed against 0X0FF

0

Commented:
you can get the original back by XOR again with the same

the following prog will demostrate

int main(){
char szTest[]={
'T'          ^ ( char) 0x0FF,
'E'          ^ ( char) 0x0FF,
'S'          ^ ( char) 0x0FF,
'T'          ^ ( char) 0x0FF,
};

for(int i = 0; i < 4; i ++){
szTest[i]^= 0x0FF;
}

for(int i = 0; i < 4; i ++){
cout<<szTest[i]<<endl;
}

return 0;
}
0

Author Commented:
I see!  Thanks to each of you for the help.  I don't like having to choose between numerous good answers, so I'm increasing to 300 pts and giving 100 to each.  Thanks again!

Regards,
Tony
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.