C# help

Miscellaneous Forums/General Discussion/C# help

I know I know... blitz forums but this is really the only community I know of that seems to know what their talking about usually. Basically I am trying to write a program to convert a string to a hexadecimal to use as WEP keys for routers. For example:

Text : "santa"

64 bit hex : "DA3011B523"



And I have a form the user will enter data into I want to then have the form to to a website automatically tell it what part of the site to go to and then fill in the info and press the save button on the website, is this possible? and if it is how do I do it.


I'm pretty new to C# but would really like to get this going.

This should work for your string to hex conversion. You just need to make a nice self contained method from it.
string input = "santa"; 
 
System.Text.StringBuilder hexOutput = new System.Text.StringBuilder(); 

byte[] byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(input); 

for (int i = 0; i <= byteArray.Length - 1; i++) { 
    hexOutput.Append(byteArray[i].ToString("x")); 
}

Response.Write(hexOutput.ToString());
I haven't got C# to hand unfortunately, so it's possible I've made a few typos.

ckob, you might want to give www.devcrunch.com a try. We have a .NET section, and yes theres a large number of helpful people on dc who know what they're talking about ;)

www.gamedev.net also has a good .NET section.

well like I said im new to c# so what exactly are you talking about when you say "you just need to make a nice self contained method from it"

method is synonomous with function.

I know what a method is but i'm not sure how I would create one to use that above chunk of code.

class YourClass
{
	static string StringToHexString( string input )
	{
		//I dont bother with stringbuilder for small cases like this... just matter of opinion ;)
		string output = "";

		byte[] byteArray = System.Text.ASCIIEncoding.ASCII.GetBytes(input); 

		for( int i = 0; i < byteArray.Length; i++ )
		{ 
		    output += byteArray[i].ToString("X2");
		}

		return output;
	}
}


ok got it working now I just need it to output a 64 bit hexadecimal number. This site
http://www.powerdog.com/wepkey.cgi

Is what I have been using but I would like the program to do it instead. With the current function and using "santa" I get 73616E7461 which doesn't seem to be correct.

ckob, assuming you just want each character to be converted into hex( which is what I assumed most routers do anyways )-- ^^that code is working 100%.

I also ran the phrase santa thru a blitz version and this wep gen: http://www.andrewscompanies.com/tools/wep.asp

I get the same 73616E7461 for each of them.

you should read this: http://www.velocityreviews.com/forums/t6559-wep-encryption.html

73616E7461 looks right, to me. That's just a set of five ASCII codes in hex representation, i.e:

$73 = Chr(115) = 's'
$61 = Chr(97) = 'a'

etc...

any ideas on the inputing to a website stuff? now that you've all helped so well with the hexadecimal stuff.

Also this doesn't seem to work, I may have set it up wrong but the WEP should always be 10 characters long and this generates characters or numbers for every character in the string I pass which isn't correct.

Google is awesome.

http://www.codeproject.com/csharp/wepkey_generator.asp

That was the first place I looked and that project doesn't seem to work either. :(