>>>>>>>>If all this function does is encrypt a password there are lots of examples written in c# out there ( Google is your friend )
>>>>>>>
>>>>>>>I did but so for I could not find a simple enough c# encrypt function that can be "duplicated" in VFP. You see I need a function that would do the same from VFP and c# end.
>>>>>>>Thank you.
>>>>>>
>>>>>>Presumably you mean that the C# version should be usable with strings already encoded using the VFP cipher library that you mentioned?
>>>>>>
>>>>>>Al's pointer to Rick's paper is still valid - you could create a small VFP com interop which could be accessed from .net.
>>>>>>
>>>>>>But which functions of that library do you actually use ? - the core encryption is fairly straightforward.
>>>>>>I took a look at the original C code and it would seem that a C# version should be simple enough to implement......
>>>>>
>>>>>The function cipher() I am using in VFP code is written in VFP; not in C. Maybe Sergey also wrote it in C but the one he recommended to me years ago was the VFP function. To be honest, I don't even understand all VFP functions he used in creating the cipher(). So converting/rewriting it to C# would be a great challenge.
>>>>
>>>>The VFP code was based on a C conversion and there's a link to the C source - you might find that easier to convert to C# (or not :-} )
>>>
>>>Do you know where I can find the DLL (I presume tha the C code was built into a DLL) file that uses this C code? And maybe it has the C code there as well.
>>
>>Does this work (not properly tested and could certainly be improved):
using System;
>>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.ASCII.GetBytes(tcStr);
>> int tcStrLength = tcStrBytes.Length;
>>
>> string lcPassword = tcPassword + '0';
>> byte[] lcPasswordBytes = Encoding.ASCII.GetBytes(lcPassword);
>> int lnPassLen = lcPasswordBytes.Length - 1;
>>
>> int lnPassPos = 0;
>>
>> string lcStrOut = string.Empty;
>>
>> int lnPassNum = ((CipherGetPnum(lcPassword)/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]);
>> lnByte = lnByte & 0xFF;
>> lcStrOut = lcStrOut + (lnByte == 0 ? Convert.ToChar( tcStrBytes[i + 1]) : Convert.ToChar(lnByte));
>> lnPassPos = lnPassPos>=lnPassLen ? 1:lnPassPos + 1;
>> }
>> return lcStrOut;
>> }
>>
>> private int CipherGetPnum(string tcStr)
>> {
>> byte[] ascii = Encoding.ASCII.GetBytes(tcStr);
>> int liRet = 1 + ascii.Select((t, i) => t + i).Sum();
>>
>> while (liRet < PwMinNum)
>> {
>> liRet = liRet << 1;
>> }
>> return liRet;
>> }
>> }
>>}
>
>Thank you for the code. As I just mentioned in my reply to myself that I found the code that I did about 6 months ago. I will compare my code to your code. I take my hat off to you as you have done it in less than an hour and I remember it took me at least 2 days to write my C# code (and million of Google searches). Thank you!
Think I've got one error in there. Should be:
lnPassPos = lnPassPos>=lnPassLen ? 0:lnPassPos + 1;