Re: Microsoft.VisualBasic.Strings.Asc ?
- From: "James" <noone@xxxxxxxxxxx>
- Date: Fri, 2 Jan 2009 12:42:01 -0500
interesting, thank you for the input.
"Göran Andersson" <guffa@xxxxxxxxx> wrote in message news:O$$zeGuaJHA.3952@xxxxxxxxxxxxxxxxxxxxxxx
James wrote:Hello,
I'm trying to put together a simple utility to do rc4 encryption based on the rc4 algorithm here:
http://aspnet.4guysfromrolla.com/articles/091802-1.3.aspx
that article is about porting Mike Shaffer's VBScript RC4 to c#... I'm using that code to make the class but use in a windows form. Using MS Visual C# Express edition sp1.
so the problem I get when compiling the class is from the use of Microsoft.VisualBasic.Strings.Asc(), like the following line:
key[a] = Microsoft.VisualBasic.Strings.Asc(ctmp);
The error I get is:
"The type or namespace name 'Strings' does not exist in the namespace 'Microsoft.VisualBasic' (are you missing an assembly reference?)"
this function is used a few times within the class. I am not a real experienced csharper and literally just installed this c# express edition to do this little thing... any help would be greatly appreciated. I did include the 'using Microsoft.VisualBasic;' include directive at the top to include the namespace.
This is the source code:
http://aspnet.4guysfromrolla.com/code/rc4encrypt.cs.htm
I'm trying to compile this so I can wire it up for use in a windows form app. (I know .net has builtin support for many crypto algorithms but the original vbscript version of this RC4 'like' algorithm is already in use for something which this utiltiy I want to make will be used for.
any input would be appreciated. thanks.
I think that you should look at the original code and convert it yourself, instead of reading that article. The author is obviously not very experienced in C#.
For example, look at this code:
char ctmp = (strPwd.Substring((a % intLength),1).ToCharArray()[0]);
It does several steps that are completely unneccesary. You don't need to use Substring to access a single character in a string, and you don't need ToCharArray to convert a single character string to a character.
The default indexer of a string is the Chars collection, so you can access the characters just as if the string was an array of characters:
char ctmp = strPwd[a % intLength];
However, the code shouldn't do this operation at all. Instead of gettings a character at a time and encoding into bytes, it should first encode the entire string and the work with the encoded bytes. This will remove the entire problem with the Asc and Chr functions.
Actually, the encryption methods in the .NET framework doesn't take strings at all, they encrypt streams of bytes, so the method should probably do the same and leave the encoding to the one using the method.
Another example, a comment says: "Note that we need to use a different variable since we've already declared a above." That's simply not true as the variables exist in separate scopes.
--
Göran Andersson
_____
http://www.guffa.com
.
- Prev by Date: Re: Microsoft.VisualBasic.Strings.Asc ?
- Next by Date: Re: XMLElement
- Previous by thread: Re: Microsoft.VisualBasic.Strings.Asc ?
- Next by thread: Debugging ResolveManifestFiles problem
- Index(es):
Relevant Pages
|