What does Xor do, I think it has something to do with encryption, but i am not sure.
thanks for any replies.
Printable View
What does Xor do, I think it has something to do with encryption, but i am not sure.
thanks for any replies.
This is bitwise exclusion.
For example, 23 Xor 50...
To calculate this, you convert both numbers to binary.
23 = 010111b
50 = 110010b
The Xor rules are: 0 Xor 0 = 0, 1 Xor 0 = 1, 0 Xor 1 = 1, 1 Xor 1 = 0.
010111
110010
======Xor
100101
100101 is 37. Try the calculator, do a 23 Xor 50, and you'll get 37. It's useful with logical, too:
True Xor True = False
True Xor False = True
False Xor True = True
False Xor False = False
thank you.
how is it used in encryption?
Dennis! You can look at my encryption samples at my page, I have my string xoring against any key.
thanks.
I use VB6 under Windows 98, 2nd edition.
Xor can be used for encryption using a string or binary value (Key) known to both the sender and the receiver of a message. Xor has the following properties.
(Readable message)Xor(Key) = Unreadable garbage.
(Unreadable garbage)Xor(Key) = Original message.
The original message is first broken into chunks, each the same length as the Key (Pad last chunk with spaces, if necessary). Xor using Key versus each chunk. Send resulting garbage. Receiver breaks garbage into chunks. Xor using Key versus each chunk, resulting in original message.
The code I have seen converts string data into binary or hex data prior to Xor operations, and then sends the garbage as a binary file. There might be some reason for the conversion, but I am not sure. Perhaps some languages do not allow Xor versus string data (does VB allow it?). Perhaps weird side effects can occur with a string containing binary garbage (garbage bytes could look like control data).
I hope the above gives you a clue.
The reason the string is converted first, is while vb uses unicode for strings. Each character is 2 bytes, and if you use the western characterset, 1 byte is empty (0). This way the key can be found easily.
Guv, don't be afraid of Binary or Hex data, it's usually a form you never get in touch with in vb as it automatically converts it to either dec or string. Also to use Xor with strings, does not apply in vb, you need to convert the strings to byte array first with strconv, as i meantioned theres a fast and good example on my homepage