Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to call VFP function from .NET C# code?
Message
 
 
À
06/01/2015 14:36:52
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01612997
Message ID:
01613189
Vues:
63
>>>>>>I know my code works because I tested it and it is in production at several customers. However, I will double check that I am not missing something important, based on your finding. Thank you.
>>>>>
>>>>>My slightly modified version of the Encrypt function:
        public string Encrypt(string tcStr, string tcPassword)
>>>>>        {
>>>>>            byte[] tcStrBytes = Encoding.ASCII.GetBytes(tcStr);
>>>>>            int tcStrLength = tcStrBytes.Length;
>>>>>
>>>>>            string lcPassword = tcPassword + ((char) 0).ToString();
>>>>>            byte[] lcPasswordBytes = Encoding.ASCII.GetBytes(lcPassword);
>>>>>
>>>>>            int lnPassLen = lcPasswordBytes.Length;
>>>>>            int lnPassPos = 0;
>>>>> 
>>>>>            string lcStrOut = string.Empty;
>>>>>
>>>>>            int lnPassNum = ((CipherGetPnum(tcPassword)/997 - 1)%254) + 1;
>>>>>
>>>>>            for (int i = 0; i < tcStrLength; i++)
>>>>>            {
>>>>>                int lnNum01 = ((lnPassNum + (i - tcStrLength)) - 1);
>>>>>                lnPassNum = (Math.Abs(lnNum01)%254)*Math.Sign(lnNum01) + 1;
>>>>>                var lnByte = tcStrBytes[i] ^ (lnPassNum ^ lcPasswordBytes[lnPassPos]);
>>>>>                lcStrOut = lcStrOut + Convert.ToChar(lnByte==0 ? tcStrBytes[i] : lnByte & 0xFF);
>>>>>                lnPassPos = lnPassPos > lnPassLen ? 0 : lnPassPos + 1;
>>>>>            }
>>>>>            return lcStrOut;
>>>>>        }
Quick test comparing results with the VFP version using string 'Test' and password 'Viv' shows identical results in VFP (returned asc values: 255,246,253,131) i.e. string length is 4. Your C# only returns first three values (i.e. string length 3)
>>>>
>>>>I am testing your code and mine code and neither one works :). I am sure it is me. Here is how I test it, please let me know if this is the correct approach:
>>>>
>>>>string cTest1 = "ABC123";
>>>>string cTest1Encr;
>>>>string cTest1Decr;
>>>>cTest1Encr = Encrypt( cTest1, "123abc");
>>>>cTest1Decr = Encrypt( cTest1Encr, "123abc");
>>>>
>>>>
>>>>Shouldn't cTest1Decr show "ABC123"?
>>>
>>>Aren't you encrypting the values instead of decrypting the 2nd?
>>
>>The second parameter is the password string. The first one is the value.
>
>Too late to play tonight - I'll get back to you in the morning (my morning :-} )

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform