Solved

C# to foxpro

Posted on 2010-11-08
2
395 Views
Last Modified: 2012-05-10
One of my clients have got a application that I think is developed in C# and has asked if I can create a tool that will encrypt a file and has the code that currently encrypts it in C#, I am not the best C# developer and not sure how to convert it to VFP 9.

Any help or guidance would be great.

Thanks!
private string encrypt(string sSource)
    {
        int nLength = sSource.Length;

        byte[] dataByte = StrToByteArray(sSource);

        System.Text.StringBuilder encryptData = new System.Text.StringBuilder();

        for (int i = 0; i < dataByte.Length; i++)
        {
            int asciiValue = (int)dataByte[i];
            if (asciiValue < 0)
            {
                asciiValue = asciiValue + 256;
            }
            asciiValue++;
            if (asciiValue == 256)
            {
                asciiValue = 0;
            }

            switch (asciiValue.ToString().Length)
            {
                case 0:
                    break;
                case 1:
                    encryptData.Append("00" + asciiValue.ToString());
                    break;
                case 2:
                    encryptData.Append("0" + asciiValue.ToString());
                    break;
                case 3:
                    encryptData.Append(asciiValue.ToString());
                    break;

            }
        }
        return encryptData.ToString();
    }

Open in new window

0
Comment
Question by:Bart-Rouan
2 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 34085211
This cannot be called encryption... and even with no C# knowledge this is an easy task:
PROCEDURE encrypt

LPARAMETERS lcString



*-- 	private string encrypt(string sSource)

*-- 	    {

*-- 	        int nLength = sSource.Length;



*-- 	        byte[] dataByte = StrToByteArray(sSource);



*-- 	        System.Text.StringBuilder encryptData = new System.Text.StringBuilder();



LOCAL lnI, lnAscii, lcOutput

lcOutput = ""



FOR lnI = 1 TO LEN(lcString)

*-- 	        for (int i = 0; i < dataByte.Length; i++)

*-- 	        {

*-- 	            int asciiValue = (int)dataByte[i];

*-- 	            if (asciiValue < 0)

*-- 	            {

*-- 	                asciiValue = asciiValue + 256;

*-- 	            }

  lnAscii = ASC(SUBSTR(lcString, lnI, 1))

  IF lnAscii = 256

    lnAscii = 0

  ENDIF

*-- 	            asciiValue++;

*-- 	            if (asciiValue == 256)

*-- 	            {

*-- 	                asciiValue = 0;

*-- 	            }



  lcOutput = lcOutput + TRANSFORM(lnAscii, "@L 999")

*-- 	            switch (asciiValue.ToString().Length)

*-- 	            {

*-- 	                case 0:

*-- 	                    break;

*-- 	                case 1:

*-- 	                    encryptData.Append("00" + asciiValue.ToString());

*-- 	                    break;

*-- 	                case 2:

*-- 	                    encryptData.Append("0" + asciiValue.ToString());

*-- 	                    break;

*-- 	                case 3:

*-- 	                    encryptData.Append(asciiValue.ToString());

*-- 	                    break;



*-- 	            }

*-- 	        }

NEXT



RETURN lcOutput

*-- 	        return encryptData.ToString();

*-- 	    }

Open in new window

0
 

Author Comment

by:Bart-Rouan
ID: 34085359
Hi,

Thanks a mill, I didn't even gave it a look but thanks anyway.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Occassional errors in VFP 9 8 996
Javascript errors in VFP form using oleControl 9 867
FORM caption height 4 191
filling in gaps in tables vfp 9 79
Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now