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. #1
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020

    The '^' operator.....

    Hi,

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

    thnx

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    227
    most likely itz math... going to the 3rd power or maybe to the 2nd power who knowz...(correct me if im wrong)

  3. #3
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    >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. #4
    B26354 Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633
    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.
    Jason Deckard

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > 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. #6
    Unregistered
    Guest
    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. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    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.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    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. #9
    www.entropysink.com
    Join Date
    Feb 2002
    Posts
    605
    This may be what you're looking for.

    Link to PDF

    Hope it helps.

    Cheers,

    Rob.
    Visit entropysink.com - It's what your PC is made for!

  10. #10
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825

  11. #11
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Cool thnx for that link, it has free sample chapters.

  12. #12
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >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.

  13. #13
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    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
    When I close my eyes nobody can see me...

  14. #14
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    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
    When I close my eyes nobody can see me...

  15. #15
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    >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 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 01:14 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 07:38 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21