|
-
Mar 9th, 2010, 05:31 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] XOR'ing in C#
Hi I need little help here
Here is my given string "8f43ae1a3319c649cc57408b6a392d6b"
8f xor 33 xor cc xor 6a =1a
43 xor 19 xor 57 xor 39 =34
ae xor c6 xor 40 xor 2d =05
1a xor 49 xor 8b xor 6b =b3
1a3405b3 and 1ffffff or 2000000 = 23405B3
How to apply that using C#?
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
-
Mar 9th, 2010, 07:24 AM
#2
Re: XOR'ing in C#
Hi, Try this, it should help you get going. What I did is I used regular expressions to split your input string and then I used two FOR loops to get the values the same way you posted.
csharp Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte[] valuearray = new byte[4];
string s = "8f43ae1a3319c649cc57408b6a392d6b";
Regex rx = new Regex(@"\w{2}");
MatchCollection mc = rx.Matches(s);
int n = mc.Count / 4;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
valuearray[j] = Convert.ToByte(mc[i + (j * n)].Value, 16);
}
int value = valuearray[0] ^ valuearray[1] ^ valuearray[2] ^ valuearray[3];
MessageBox.Show(value.ToString("X2"));
}
}
}
}
I didn't do that part though :
Code:
1a3405b3 and 1ffffff or 2000000 = 23405B3
as I don't know where you got the last 2 values from, but I think you should be able to figure it out with the sample I posted.
I hope this helps you.
Last edited by stlaural; Mar 9th, 2010 at 07:27 AM.
Reason: cause I can
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Mar 9th, 2010, 08:40 AM
#3
Thread Starter
Hyperactive Member
Re: XOR'ing in C#
It works
BTW I modify some to suite my needs thanks.
Code:
private void button2_Click(object sender, EventArgs e)
{
byte[] valuearray = new byte[4];
string s = "8f43ae1a3319c649cc57408b6a392d6b";
Regex rx = new Regex(@"\w{2}");
MatchCollection mc = rx.Matches(s);
StringBuilder sb = new StringBuilder();
int n = mc.Count / 4;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
valuearray[j] = Convert.ToByte(mc[i + (j * n)].Value, 16);
}
int value = valuearray[0] ^ valuearray[1] ^ valuearray[2] ^ valuearray[3];
sb.Append(value.ToString("X2"));
textBox3.Text = sb.ToString();
}
}
1a3405b3 and 1ffffff or 2000000 = 23405B3
green color is the result of that xor
I need to AND and OR to that value to get some codes in red color
Last edited by dr_aybyd; Mar 9th, 2010 at 08:48 AM.
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
-
Mar 9th, 2010, 09:20 AM
#4
Re: XOR'ing in C#
Oh I see, its all about color. I was wondering.
Glad you got it working.
Alex
.NET developer
"No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)
Things to consider before posting.
Don't forget to rate the posts if they helped and mark thread as resolved when they are.
.Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
My fresh new blog : writingthecode, even if I don't post much.
System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0 
-
Mar 9th, 2010, 10:10 AM
#5
Thread Starter
Hyperactive Member
Re: XOR'ing in C#
I got it all works
thanks stlaural
Here is my final codes
csharp Code:
private void button2_Click(object sender, EventArgs e) { byte[] valuearray = new byte[4]; string s = "8f43ae1a3319c649cc57408b6a392d6b"; Regex rx = new Regex(@"\w{2}"); MatchCollection mc = rx.Matches(s); StringBuilder sb = new StringBuilder(); int n = mc.Count / 4; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { valuearray[j] = Convert.ToByte(mc[i + (j * n)].Value, 16); } int value = valuearray[0] ^ valuearray[1] ^ valuearray[2] ^ valuearray[3]; sb.Append(value.ToString("X2")); textBox3.Text = sb.ToString(); int myCodes = (0x1a3405b3 & 0x1ffffff) | 0x2000000; string newCodes = myCodes.ToString("X2"); String hexNumber = newCodes; int hextodecs = Int32.Parse(hexNumber, NumberStyles.HexNumber); //MessageBox.Show(i.ToString()); textBox4.Text = hextodecs.ToString(); } }
VB 6.0 = "Self-Study" Then
vb.NET = "Self-Study" Then
C# = 'on going study.....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|