title: Encrypt XOR in Delphi / Decrypt in PHP
body: <p>Ok guys, few days ago I translated my simple XOR function in Delphi for PHP and it was working fine. Today when I tried again for some unknown reason, it's broken. What I'm doing is: first I do a base64 encode in the string, then I xor it. So I send it for PHP over POST method, and in PHP I 'unxor' and decode base64. Look the function in Delphi(i'm using EncodeBase64 from EncdDecd unit):</p>
  
  <pre><code>function EncryptStr(Input: AnsiString; Seed: integer): AnsiString;
  var
  i : integer;
  Output : AnsiString;
  begin
      Input:= EncodeBase64(BytesOf(UTF8Encode(Input)),  Length(BytesOf(UTF8Encode(Input))));
      Output := '';
      for i := 1 to Length(Input) do
          Output := Output + AnsiChar(Ord(Input[i]) XOR (Seed));
      Result:= Output;
  end;
  </code></pre>
  
  <p>Ok, so I send this way over Indy HTTP(don't know if this matters, but can be useful)</p>
  
  <pre><code>procedure TForm1.DoPost;
  var
    HTTP: TIdHTTP;
    lPost: TStringList;
  begin
    Http:= TIDHttp.Create(nil);
    lPost:= TStringList.Create;
    Http.Request.UserAgent:='Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)';
    lPost.Add('PNAME=' + EncryptStr('test.exe', 232));
    lPost.Add('BYTETYPE=' + EncryptStr('UNICODE', 232));
    Http.Post('http://192.168.1.12/panel.php?uid=09ed-erty-as98-1498', lPost);
  </code></pre>
  
  <p>In PHP I receive/decrypt in this way:</p>
  
  <pre><code> function DecryptStr($str)
    {
      $key = '232'; //key need to be the same as hook is using!
      $strsize = @strlen($str);   
      $j = @strlen($key);
      for($i=$strsize-1; $i &gt;= 0; $i--)
       {
         $str[$i] = @chr(@ord($str[$i]) ^ $key);
       }
       $str = base64_decode($str);
       return $str;
      }
  
   if(isset($_POST['PNAME']) &amp;&amp; isset($_POST['BYTETYPE']) &amp;&amp; ($_POST['BYTETYPE'] != ''))
    {
      saveInfo($uid, DecryptStr($_POST['PNAME']), DecryptStr($_POST['BYTETYPE']), $con); 
    }
  </code></pre>
  
  <p>The saveInfo function is just doing some echo in the variables decrypted, but I get everything corrupted... What's wrong?</p>