Results 1 to 7 of 7

Thread: Encrypt function (vb-> C#) [Resolved]

  1. #1

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Encrypt function (vb-> C#) [Resolved]

    Hello
    Am trying to translate a vb-encrypt function to C# but I'm stuck.

    VB Code:
    1. Dim strChar, L, x
    2.      
    3.       L = Len(strKey)
    4.       For x = 1 To Len(strValue)
    5.          strChar = Asc(Mid$(strKey, (x Mod L) - L * ((x Mod L) = 0), 1))
    6.          Mid$(strValue, x, 1) = Chr$(Asc(Mid$(strValue, x, 1)) Xor strChar)
    7.       Next

    I have some trouble finding the correct functions for string manipulation.
    mid = .substring()
    chr$ = ? (is it (char) )
    ASC = ? (i think it is system.text.asciiencoding)
    mod = ? (cant find it in system.math)
    Xor = ? (cant find it in system.math)
    Last edited by onerrorgoto; Jul 8th, 2003 at 02:07 AM.
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    It's hard to translate from VB6 to C# esp . If you don't have to , then you better use the .NET way in Cryptographic class . Not that complicated . http://www.codeproject.com/csharp/Encryption.asp

  3. #3

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Unhappy Thanks

    We have already looked att the crypto-class but our problem is that the app we are translating saves the decrypted strings in a db and if we change the decrypt-function we cant read/save the values.

    that why we have to translate it
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    aha , OK . Try to convert this VB6 code into VB.NET , when you get these functions to work , save them in a class file , ship them in a dll file , then you can *I think* use it within your C# proj .

  5. #5
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    here's how to use asc / char translations in a simple button click , this may help with some of your answers .
    Code:
    private void button1_Click(object sender, System.EventArgs e)
    {
    	string message="my message ";
    	Byte[] bt = System.Text.Encoding.ASCII.GetBytes(message);         
    	for (int i=1; i!=bt.Length ; i++)
    	{
    	Console.Write(bt[i]); //// asc chars for each letter
    	string s= System.Text.Encoding.ASCII.GetString(bt, 0, i);
            MessageBox.Show(s); /// show letter converted back from asc chars.
    	}
    }
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    Code:
    System.Data.SqlTypes.SqlInt32.Mod
    thats the Mod function in c#

    Code:
    System.Data.SqlTypes.SqlInt32.Xor
    and Xor.
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  7. #7
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    mod -> % operator, ex : 3 % 1
    chr -> "myString"[0] , where 0 is the chr you want to see
    \m/\m/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width