# Thread: Xoring String

1. ## Xoring String

Hi. Which is the best way to xor two strings
which are in binary mode?
For example
Text1=011000100 01110001 ....
Text2=001010111 00100010 ...

2. ## Re: Xoring String

convert your strings in binary numbers and xor the binary numbers

3. ## Re: Xoring String

The Convert class has methods that will convert between numbers and Strings using base 2.

4. ## Re: Xoring String

By XORING I assume you mean flipping the bits. There are several ways to do that. What are you going to use that for?

5. ## Re: Xoring String

Originally Posted by Peter Swinkels
By XORING I assume you mean flipping the bits. There are several ways to do that. What are you going to use that for?
XORing two values would mean creating a result where each bit is set if and only if the corresponding bit is set in one and only one of the operands. XORing a single value is basically doing that with a second value where all bits are set.

6. ## Re: Xoring String

Originally Posted by Peter Swinkels
By XORING I assume you mean flipping the bits. There are several ways to do that. What are you going to use that for?
I have two messages and I want to XOR them(kind of encryption) but the two messages each character is in binary mode.

7. ## Re: Xoring String

Originally Posted by requiem78
I have two messages and I want to XOR them(kind of encryption) but the two messages each character is in binary mode.
What do you mean by "binary mode"? Are you talking about actually binary data, as opposed to text containing "1" and "0" characters? Are you aware that XORing two arbitrary values is a one-way process, i.e. you cannot get the original values back again? If you have one arbitrary value and one known value then you can use the known value to get the arbitrary value again.

8. ## Re: Xoring String

Originally Posted by jmcilhinney
What do you mean by "binary mode"? Are you talking about actually binary data, as opposed to text containing "1" and "0" characters? Are you aware that XORing two arbitrary values is a one-way process, i.e. you cannot get the original values back again? If you have one arbitrary value and one known value then you can use the known value to get the arbitrary value again.
Assume that the one string is Hallo and its binary str1="01001000 01100001 01101100 01101100 01101111"
the other is World and its binary str2="01010111 01101111 01110010 01101100 01100100"

and I want the str1 XOR str2

9. ## Re: Xoring String

Originally Posted by requiem78
Assume that the one string is Hallo and its binary str1="01001000 01100001 01101100 01101100 01101111"
the other is World and its binary str2="01010111 01101111 01110010 01101100 01100100"

and I want the str1 XOR str2
Here is a solution. It should be apparent that this only works if the strings are the same.

Code:
```        Dim s1 As String = "hello"
Dim s2 As String = "world"

Dim b1() As Byte = System.Text.Encoding.Default.GetBytes(s1)
Dim b2() As Byte = System.Text.Encoding.Default.GetBytes(s2)
Dim rslt As New List(Of Byte)
For x As Integer = 0 To b1.Length - 1
Next
Stop
'decode
For x As Integer = 0 To b2.Length - 1
rslt(x) = rslt(x) Xor b2(x)
Next```

10. ## Re: Xoring String

I don't understand why you would want to do this because .NET has built-in support for encryption which is fairly easy to use and much more secure.

11. ## Re: Xoring String

Originally Posted by dday9
I don't understand why you would want to do this because .NET has built-in support for encryption which is fairly easy to use and much more secure.
9 times out of 10, a question like this is part of a homework assignment. A quasi-nonsensical objective that demonstrates the ability to solve a problem using previously learned (and potentially disparate) concepts.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width