Hi there,
I was wondering if someone knows the C# equivalent for charCodeAt. This is een JScript method
that converts an string to Unicode and encodes this at base 16 (toString(16))
This project generates strong (WEP) key's for protecting WIFI access points.
Anyone got a clue??
Help would be appreciated!
Mark van den Broek
mvdbroek@kg.nl
This is the original JScript source
// generate a WEP key with the specified key length in bytes
//(5/13/16/29 bytes for 64/128/152/256-bit WEP
function gen_key(keyLengthInBytes) {<br />
for (i = 0; i < keyLengthInBytes; i++)<br />
{<br />
ascWEPkey += charArray[gen_prn()]; <br />
}<br />
<br />
for (i = 0; i < ascWEPkey.length; i++)<br />
{<br />
hexWEPkey += ascWEPkey.charCodeAt(i).toString(16);<br />
}<br />
}
This is what i got so far
private string ASCII_KEY, HEX_KEY;<br />
private char[] charArray = new char [95] { <br />
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')','*', '+', ',', '-', '.', '/', <br />
'0', '1', '2', '3', '4', '5', '6', '7','8', '9', ':', ';', '<', '=', '>', '?', <br />
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', <br />
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', <br />
'\'', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', <br />
'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'};<br />
<br />
private void GenerateWEPKey(int KeyLength) {
for (int i = 0; i < KeyLength; i++) {<br />
ASCII_KEY += charArray[GenPseudoNo()];
}<br />
for (int i = 0; i < ASCII_KEY.Length; i++) {<br />
HEX_KEY += charCodeAt(ASCII_KEY,i);
}<br />
MessageBox.Show(HEX_KEY);<br />
}<br />
<br />
private int GenPseudoNo() {<br />
Random rdm = new Random();
return (int)Math.Floor(rdm.NextDouble() * charArray.Length);
}<br />
<br />
private string charCodeAt(string ASCII, int index) {<br />
System.Text.ASCIIEncoding AE = new System.Text.ASCIIEncoding ( );<br />
byte [ ] alphabetArray = AE.GetBytes ( ASCII );<br />
System.Text.StringBuilder sb = new System.Text.StringBuilder();<br />
<br />
for ( int x = 0; x <= alphabetArray.Length - 1; x++ ) {<br />
sb.Append ( string.Format ( "{0}", alphabetArray [ x ]));<br />
}<br />
return sb.ToString(index,2);<br />
}
|