473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Need Help Encrypting String

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[i] = 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[i] = (char)(password[i % password.Length] ^
binary[i]);
}
return new string(chars);
}

Dec 26 '06 #1
3 1246
<ma**********@gmail.comwrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 27 '06 #2
This is kind of the same... still having problems with teh Encryption
problems...

Jon wrote:
<ma**********@gmail.comwrote:
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?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 27 '06 #3
The questions above is solved.

Thanks

Dec 27 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dayne | last post by:
Guys, I am writing a database application(vb.net , sql server) and is presently storing the connection settings in a xml file...not very secure though. What is a safer method in a dynamic...
4
by: Andy G | last post by:
If users forget there passwords I want to send a link to them through email so they can click on a link and go to a change password page. eBay does this by sending you a url that looks something...
7
by: Bob Hollness | last post by:
OK, this has me pulling my hair out. All I want to do is encrypt/decrypt strings. They may be up to 400 characters in length though. So, I assume System.Security.Cryptography is the one to use....
10
by: Nemok | last post by:
Hi, I am trying to write an additive encryption algorithm in C++ that will encrypt a text by adding a random numer to each character in a string. The code looks similar to this: for(int...
11
by: frizzle | last post by:
Hi there, I need an encrypting function, but haven't got a clue where to start. First a string has to be encrypted with two different encryption keys. Both output should be anything a-z / A-Z /...
3
by: Thirsty Traveler | last post by:
I hear that MD5 is not recommended for encrypting database passwords in that it can be compromised. Does anyone have a recomendation (SHA-1, etc.) on an algorithm that would be more appropriate.
5
by: Chris Dunaway | last post by:
I have an application which is installed on a network share to be run from one or more workstations. I have granted trust to the applications on the workstations and the appropriate permissions on...
8
by: manmit.walia | last post by:
Hello Everyone, Long time ago, I posted a small problem I had about converting a VB6 program to C#. Well with the help with everyone I got it converted. But I overlooked something and don't...
2
by: SeeSharp Bint | last post by:
Visual Studio 2005, dotnet, c#. Microsoft SQL Server. Windows XP forms application. Temporarily, for my database application, I have been storing the various elements of database connection...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.