Avatar of rares_dumitrescu
rares_dumitrescu asked on

Convert Visual Basic function to PHP

I have the next function in Visual Basic 6.0

Private Function DecryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

#If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

#End If

    'Decrypt string
    If Len(strPwd) Then
        For i = 1 To Len(strText)
            c = Asc(Mid$(strText, i, 1))
            c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
            strBuff = strBuff & Chr$(c And &HFF)
        Next i
    Else
        strBuff = strText
    End If
    DecryptText = strBuff
End Function

I want to convert this to PHP
PHPVisual Basic.NET

Avatar of undefined
Last Comment
Robin

8/22/2022 - Mon
brad2575

I have most of it but not sure what you are doing on these 3 lines, if you could explain it would be easier.

$c = Asc(Mid$(strText, i, 1));
/$c = $c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1));
$strBuff = $strBuff & Chr$(c And &HFF);

Function DecryptText($strText, $strPwd){
    //#If Not CASE_SENSITIVE_PASSWORD Then
 
    //Convert password to upper case
    //if not case-sensitive
    $strPwd = strtoupper($strPwd);
	
//#End If
 
    //Decrypt string
    If(strlen($strPwd) > 0){
        for($i = 1; $i<= strlen($strText); $i++){ 
    	    //$c = Asc(Mid$(strText, i, 1));
            //$c = $c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1));
            //$strBuff = $strBuff & Chr$(c And &HFF);
            $i = $i + 1;
        } // next loopNext i
    }Else{
        $strBuff = $strText;
    } //End If
    $DecryptText = $strBuff;
} //End Function

Open in new window

ASKER CERTIFIED SOLUTION
brad2575

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Robin

Sorry brad2575.
I opened the question. Had no answers. Started to create the php function.
That took a little time ;), and posted it, not seeing your 2 comments.

Robin
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes