Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to call VFP function from .NET C# code?
Message
De
07/01/2015 13:08:48
 
 
À
07/01/2015 10:11:27
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:
01613251
Vues:
66
>>>>>>>>>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 :-} )
>>>>
>>>>Encoding problem when char values > 128. This should work. Didn't look at your code I'm afraid:
using System;
>>>>using System.Collections.Generic;
>>>>using System.Linq;
>>>>using System.Text;
>>>>
>>>>namespace Cipher
>>>>{
>>>>    public class Cipher
>>>>    {
>>>>        private const int PwMinNum = 1000;
>>>>
>>>>        public string Encrypt(string tcStr, string tcPassword)
>>>>        {
>>>>            byte[] tcStrBytes = Encoding. GetEncoding(1252).GetBytes(tcStr);
>>>>            int tcStrLength = tcStrBytes.Length;
>>>>
>>>>            string lcPassword = tcPassword + ((char) 0).ToString();
>>>>            byte[] lcPasswordBytes = Encoding.GetEncoding(1252).GetBytes(lcPassword);
>>>>
>>>>            int lnPassLen = lcPasswordBytes.Length;
>>>>            int lnPassPos = 0;
>>>>            int lnPassNum = ((CipherGetPnum(lcPasswordBytes)/997 - 1)%254) + 1;
>>>>
>>>>            byte[] bytes = new byte[tcStr.Length];
>>>>
>>>>            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]);
>>>>                bytes[i] = lnByte==0 ? tcStrBytes[i] : (byte) (lnByte & 0xFF);
>>>>                lnPassPos = lnPassPos > lnPassLen ? 0 : lnPassPos + 1;
>>>>            }
>>>>            return Encoding.GetEncoding(1252).GetString(bytes);
>>>>        }
>>>>
>>>>        private int CipherGetPnum(IEnumerable<byte> ascii)
>>>>        {
>>>>            int liRet = 1 + ascii.Select((t, i) => t + i).Sum();
>>>>            while (liRet < PwMinNum)
>>>>            {
>>>>                liRet = liRet << 1;
>>>>            }
>>>>            return liRet;
>>>>        }
>>>>    }
>>>>}
>>>
>>>Thank you very much. Your code works; almost 100%. Except when a string that you are trying to encrypt has more than 2 spaces
>>>(e.g."ABC123 ", 3 spaces after '3'), it produces error. Btw, if the string has only 2 empty spaces, no error. E.g. "ABC123 " (two spaces after 3), no error.
>>
>>Duh. Can't count - I was exceeding password length :-{ .
>>Two changes should fix:
int lnPassLen = lcPasswordBytes.Length - 1;
>>//and
>>lnPassPos = lnPassPos == lnPassLen ? 0 : lnPassPos + 1;
>
>Increment lnPassPos in the for clause ?
>
> for (int i = 0; i < tcStrLength; i++, lnPassPos++ )
>
Could do (this is not exactly optimized code :-} ) - although it still needs to be reset to loop the password again if ness....
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform