Solved

C# to foxpro

Posted on 2010-11-08
2
432 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 42

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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fox 9  Using datetime field types 2 345
SSIS 2012 and Visual FoxPro 3 2,196
Print a word document in Visual Foxpro 1 689
Read data from Excel file with Oppen Office automation 6 210
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…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

739 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