将VBA加密功能转换为PHP

My first question here, so hopefully this all goes well.

I have an application that is currently running on desktop under MS Access using VBA code. When the user logs in I have a function to encrypt the password. This is:

Public Function EncryptEasy(strIn As String) As String

Dim strChr As String
Dim i As Integer
Dim Salt As Long
Salt = 543214321

For i = 1 To Len(strIn)
  strChr = strChr & CStr(Asc( Mid(strIn, i, 1) ) Xor Salt)
Next I

EncryptEasy = strChr

End Function

To give you an idea, when I run EncryptEasy("test") in VBA, it returns: 543214213543214228543214210543214213

I am now setting up a simple web-app using PHP and was hoping to utilise the same encryption as I'm currently using by coding this function into PHP. I HAVE tried and below is my attempt:

function EncryptEasy($strIn) {

$salt = 543214321;
$strChr = Null;
$strLen = strlen($strIn);

  for ($i = 0; $i <= $strLen; $i++) {
      $strChr = $strChr . chr(ord(substr($strIn, $i, 1)) xor $salt);
  }

  return $strChr;

}

However, this is returning blank. I have tried echoing this:

<?php
echo EncryptEasy("test");
?>

to no avail.

Is anyone able to see where I am going wrong?

I would not suggest creating your own algorithm for encrypting, instead use built-in functions provided by php.

Although this is not encrypting the password like the one in your original code, using password_hash is easier than creating your own, and to verify use password_verify()

Hashing Password:

<?php
    $hashed = password_hash("somePassword", PASSWORD_DEFAULT);
?>

Verifying Password

<?php
    if(password_verify('somePassword', $hashed))
    {
        echo 'Same'; //goes here
    } else {
        echo 'Not same';
    }
    if(password_verify('somePasswordsss', $hashed))
    {
        echo 'Same'; 
    } else {
        echo 'Not same'; //goes here
    }
?>