Re: Microsoft.VisualBasic.Strings.Asc ?



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

.



Relevant Pages

  • Re: Microsoft.VisualBasic.Strings.Asc ?
    ... I'm trying to put together a simple utility to do rc4 encryption based on the rc4 algorithm here: ... (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. ... 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. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: simple string encryption
    ... which seems to be a fast and small xor encryption algorithm. ... string into a textbox and then read the string from the textbox ... The reason is because strings in VB use two bytes per character and your code, as it stands, is messing about with both bytes of each character. ...
    (microsoft.public.vb.general.discussion)
  • Re: Encryption algorithm
    ... > character alphanumeric string in a COBOL program. ... consider these "obscuring" rather than "encryption", ... that you run the string through the same algorithm to encode and decode. ... This has the advantage of working with pretty much any character you'd ...
    (comp.lang.cobol)
  • End of String Character?
    ... string using some extended ASCII characters (ASCII code> 128) ... I am wondering if there is a reserved character in VB that signifies ... the end of a string of characters. ... Is my encryption algorithm possible generating a reserved character ...
    (microsoft.public.scripting.vbscript)
  • Re: REWARD: chr() not working for Chinese "Locale"
    ... I have a routine that encrypts a string. ... >> value the encryption routine generated for each character, ... > into a string which is likely to survive whatever you throw at it. ... >> encryption routine tries to set a character to a value in this range, ...
    (microsoft.public.pocketpc.developer)