xor strings??
-
How to make simple xor in C#? ===================== http://wasp.elcat.kg
-
How to make simple xor in C#? ===================== http://wasp.elcat.kg
Hi, If you are looking at nos. then you can use ^ operator. For strings, you need to first convert them to bytes,
ASCIIEncoding enc = new ASCIIEncoding (); byte[] keybytes = enc.GetBytes (key);
here key is of typestring
once you have converted to bytes, you can work on them. Hope this helps. Cheers Kannan -
How to make simple xor in C#? ===================== http://wasp.elcat.kg
Besides the above suggestion, you can after this, create a BitArray with the byte[] and use its Xor method. I see dumb people
-
Hi, If you are looking at nos. then you can use ^ operator. For strings, you need to first convert them to bytes,
ASCIIEncoding enc = new ASCIIEncoding (); byte[] keybytes = enc.GetBytes (key);
here key is of typestring
once you have converted to bytes, you can work on them. Hope this helps. Cheers Kannanstring txt1 = "some_text"; string txt2 = "anything_else"; ASCIIEncoding enc = new ASCIIEncoding(); ASCIIEncoding enc2 = new ASCIIEncoding(); byte[] kb1 = enc.GetBytes(txt1); byte[] kb2 = enc2.GetBytes(txt2); MessageBox.Show(kb1 ^ kb2); Operator '^' cannot be applied to operands of type 'byte[]' and 'byte[]' damm, what I did wrong? ===================== http://wasp.elcat.kg
-
string txt1 = "some_text"; string txt2 = "anything_else"; ASCIIEncoding enc = new ASCIIEncoding(); ASCIIEncoding enc2 = new ASCIIEncoding(); byte[] kb1 = enc.GetBytes(txt1); byte[] kb2 = enc2.GetBytes(txt2); MessageBox.Show(kb1 ^ kb2); Operator '^' cannot be applied to operands of type 'byte[]' and 'byte[]' damm, what I did wrong? ===================== http://wasp.elcat.kg
You need to ^ each byte, not the whole lot. You need to step through the strings, and can only perform the operation on the set of bytes that exists in both arrays, so unless the two strings are always the same length ( which they are not in your example ), I doubt you're going to get what you wanted. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002 -
string txt1 = "some_text"; string txt2 = "anything_else"; ASCIIEncoding enc = new ASCIIEncoding(); ASCIIEncoding enc2 = new ASCIIEncoding(); byte[] kb1 = enc.GetBytes(txt1); byte[] kb2 = enc2.GetBytes(txt2); MessageBox.Show(kb1 ^ kb2); Operator '^' cannot be applied to operands of type 'byte[]' and 'byte[]' damm, what I did wrong? ===================== http://wasp.elcat.kg
You will have to iterate the array and do the operations individually on every byte.
for(int i=0; i<10; i++) kb1[i] ^= kb2[i];
Cheers Kannan -
You need to ^ each byte, not the whole lot. You need to step through the strings, and can only perform the operation on the set of bytes that exists in both arrays, so unless the two strings are always the same length ( which they are not in your example ), I doubt you're going to get what you wanted. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002Ok, is there any other simple way to encode\decode some string? ===================== http://wasp.elcat.kg
-
Ok, is there any other simple way to encode\decode some string? ===================== http://wasp.elcat.kg
Yes, there is apparently heaps of encryption/decryption stuff in .NET, but I confess to not having used any of it, yet. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002