Need Help Encrypting String

M

manmit.walia

Hello All,

I have been given a file to convert to C# and being my bad luck the
file is written in VB6 which I have no idea on how to convert the file
to C#. I first thought that I would try the Visual Studio Wizard to
convert it to VB.NET then maybe convert the VB.NET to C#. But when I
used the wizard it made it even uglier. Hopefully someone can help me
convert this small function to C#. Below is what I have done so far,
hopefully I am on the right track.

Test Case:

"pass$" = 'THEFELDGROUP' and "Strg$" = 'Xperience1' the output should
be '0C3820342C292A24377E'.

VB6 Code:

Function Crypt(pass$, Strg$)
Dim a, b
Dim i As Integer

a = 1
For i = 1 To Len(Strg$)
b = Asc(Mid$(pass$, a, 1)): a = a + 1: If a > Len(pass$) Then a =
1
Mid$(Strg$, i, 1) = Chr$(Asc(Mid$(Strg$, i, 1)) Xor b)
Next

End Function

My C# Code so far:



static byte[] ConvertToHex(string _toEncrypt)
{
byte[] ret = new byte[_toEncrypt.Length];
for (int i = 0; i < ret.Length; i++)
{
ret = Convert.ToByte(_toEncrypt,16);
}

return ret;
}


static string Encrypt(string password, string decrypted)
{
byte[] binary = ConvertToHex(decrypted);
char[] chars = new char[binary.Length];
for (int i = 0; i < chars.Length; i++)
{
chars = (char)(password[i % password.Length] ^
binary);
}
return new string(chars);
}
 
J

Jon Skeet [C# MVP]

I have been given a file to convert to C# and being my bad luck the
file is written in VB6 which I have no idea on how to convert the file
to C#. I first thought that I would try the Visual Studio Wizard to
convert it to VB.NET then maybe convert the VB.NET to C#. But when I
used the wizard it made it even uglier. Hopefully someone can help me
convert this small function to C#. Below is what I have done so far,
hopefully I am on the right track.

Um, is this significantly different to the question you posted in October?
 
M

manmit.walia

This is kind of the same... still having problems with teh Encryption
problems...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top