就这几行代码,搞的小弟我一头雾水,哪位大侠懂PHP,帮忙改成D版本的

就这几行代码,搞的我一头雾水,哪位大侠懂PHP,帮忙改成D版本的.
就这几行代码,搞的我一头雾水,哪位大侠懂PHP,帮忙改成D版本的,万分感谢!!!!!!!!!!!!

function encrypt($str, $key = '123456')
{
  $coded = '';
  $keylength = strlen($key);

  for ($i = 0, $count = strlen($str); $i < $count; $i += $keylength)
  {
  $coded .= substr($str, $i, $keylength) ^ $key;
  }

  return str_replace('=', '', base64_encode($coded));
}

------解决方案--------------------
function TForm1.encrypt(str :string; key:string='123456'):string;
var
coded string;
keylength :integer; 
i :integer;
begin
Result := '';

coded :='';
keylength := = strlen(key);
i:=0;
while i<keylength do
begin
coded := coded + midstr(str, i, keylength) ^ key;
i:=i+keylength;
end;
end;
------解决方案--------------------
function Encrypt(Str :string; Key :string = '123456') :string;
var
Coded :string;
KeyLength,i :integer;
begin
Result :='';
KeyLength := Length(Key);
i :=0;
while i<Length(Str) do
begin
Coded := Coded + (Copy(Str,i,KeyLength) xor Key); 
i := i + KeyLength;
end;
Result := Replace(Base64_EnCode(Coded),'=',''); //Base64_Encode()在Delphi中没有现成的函数。
end;
------解决方案--------------------
Delphi(Pascal) code

function encrypt(str:string;key:string='123456'):string;
var
  code:string;
  xorresult,s:string;
  keylength:integer;
  i:integer;
  count:integer;
  j:integer;
begin
  code:='';
  keylength:=Length(key);
  i:=1;
  count:=Length(str)+1;//为啥米要加1,难道因为i是从1开始计数的?;
  while (i<count) do
  begin
    if count-i<keylength then
      keylength:=count-i;
    setlength(xorresult,keylength);
    for j:=1 to keylength do
    begin
      s:=copy(str,i,keylength);
      xorresult[j]:=s[j];
      xorresult[j]:=chr(ord(xorresult[j]) xor ord(key[j]));
    end;
    code:=code+xorresult;
    i:=i+keylength;
  end;
  //EncodeString()函数来源于 encddecd 单元,用来将字符串编码为base64
  //DecodeString()函数用来解码
  result:=StringReplace(EncodeString(code),'=','',[rfReplaceAll, rfIgnoreCase]);
end;