# The '^' operator.....

This is a discussion on The '^' operator..... within the C Programming forums, part of the General Programming Boards category; Hi, I often see the operator '^' used in encryption programs. WHat does it do anyway? thnx...

1. ## The '^' operator.....

Hi,

I often see the operator '^' used in encryption programs. WHat does it do anyway?

thnx

2. most likely itz math... going to the 3rd power or maybe to the 2nd power who knowz...(correct me if im wrong)

3. >most likely itz math... going to the 3rd power or maybe to the 2nd power who knowz...(correct me if im wrong)

Itz the XOR operator, diz-awg. Word.

4. Originally posted by Govtcheez
Itz the XOR operator, diz-awg. Word.
Yo yo yo, peeps can get the 411 on dat right here. Peace out.

5. > Yo yo yo, peeps can get the 411 on dat right here. Peace out.

Mad propz to mah man J to the D, for keepin it real! Dat is da shiz-nit, yo! Break it down.

6. It's the bitwise exclusive OR operator. It sets a bit if and only if one of the bits in the corresponding operands are set. An example:

105^44

1101001
0101100
-----------
1000101

The bit is only set if exactly one of the bits is 1.

Compare this with the bitwise OR (105 | 44)

1101001
0101100
-----------
1101101

The bit is set if 1 or both bits is 1.

7. The reason it is used in some encryption programs is that it is easy to do. You can XOR a plain-text message with some key to get an encrypted-text message, and then later XOR the same key with the encrypted message to reproduce the plain-text message. IE, "Hi" ^ some key = encrypted data, encrypted data ^ some key = "Hi".

It is easy to implement an encryption program this way but is hardly secure and relatively easy to break (crack). Use this method if you are having fun and learning about encryption - avoid it like the plague if you are trying to develop an application you intend to distribute to others or just use yourself that would require real security.

If you need real security, use something like Rijndael (pronounced similar to rhine-doll). You can do a search for it on the net and download the source code for free. It can provide you with 128, 192, or 256-bit encryption and was the new US government standard the last I had heard (which was probably around a year or so ago, there may likely be something new in use, who knows) replacing the old 56-bit DES(?) algorithm.

8. I did a search for it but i couldn't find the algorithm. I can get some C code on it but they are a bit too hard for me at the current stage.

9. This may be what you're looking for.

Hope it helps.

Cheers,

Rob.

10. Cool thnx for that link, it has free sample chapters.

11. >I did a search for it but i couldn't find the algorithm

You couldn't??

Then you probably didn't use Google, since it comes up with a huge list of results. Here's the link to the inventors of the Rijndael algorithm.

http://www.esat.kuleuven.ac.be/~rijmen/rijndael/

>rhine-doll

I think rhine-dahl is better pronounciation.

12. XOR is also very useful to swap the values of two variables without any temporary variable:
Code:
```/* swaps the values of a and b */
a^=b;
b^=a;
a^=b;```
klausi

13. originally posted by hk_mp5kpdw:
It is easy to implement an encryption program this way but is hardly secure and relatively easy to break (crack).
Thatīs wrong.
The only really uncrackable (it was proved mathematically) encryption works with simple XOR-encryption. The difficulty with it is, that you need a key that is produced randomly and that the key has to have the same size than the secret message. This encryption is called "One-Time-Pad", because you can use the key only once. If you use it twice, your encryption is nearly worthless because itīs very easy to crack then.
Here is some more to read. Itīs a discussion about it at this message board. We said some more details about the One-Time-Pad (OTP) there.

klausi

14. >If you use it twice, your encryption is nearly worthless because
>itīs very easy to crack then.

I do not really agree with this, because since it is theoretical impossible to crack the key, you can use the key twice and more.

The main reason that it is called one-time-pad is that it was invented long before e-mail and that kind of electronic communication was invented.

So if an army, government or other organisation wanted to communicate in a secure way with using OTP, someone had to bring the key from A to B. People can forget something, people can get caught, people can be killed etc. So there was always a chance that the key fell into hands of the opponent.

When you're communicating with more than one group, you needed more people to distribute the keys. If one got caught and you were using the same keys, than all messages could be cracked. That's why there were used a lot of keys, one for each group.

A different situation is that if you have for example 3 companies, A, B and C and company A distributes the same key to B and C. Then B is able to crack communication between company A and C and C is able to crack communication between A and B. This is a situation A probably doesn't want. So A sets up a secure communication pad between A and B and a secure communication pad between A and C.

Page 1 of 2 12 Last