Hi,
ich habe diese delphi-Funktion:
// --------------------------------------------------------
Function Encryp(Const S: String; Key: Word; rueckw: Boolean): String;
Var
I: byte;
oben, unten: byte;
Begin
Setlength(Result, length(S));
If Rueckw Then Begin
For I := Length(S) Downto 1 Do Begin
Result[I] := char(byte(S[I]) Xor (Key Shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
End;
End
Else Begin
For I := 1 To Length(S) Do Begin
Result[I] := char(byte(S[I]) Xor (Key Shr 8));
Key := (byte(Result[I]) + Key) * C1 + C2;
End;
End;
Encryp := result;
End;
// ---------------------------------------------------------
Nun will ich die aus PHP umschreiben. Hier mal ein Versuch:
<!-- ----------------------------- -->
<textarea rows="27" name="S1" cols="70"><?php
$c1=41088;
$c2=88104;
Function encryp($s,$key,$rueckw){
global $c1,$c2;
if ($rueckw) {
For ($i=0;$i<=strlen($s)-1; $i++){
$result.=chr(substr($s,$i,1) ^ ($key >> 8) & 0xff);
$key = ((ord(substr($result,-1))+$key)*$c1 + $c2) & 0xffff;
echo "$key ".($key >> 8)."\n";
}
} else {
For ($i=strlen($s)-1;$i>=0; $i--){
$result.=chr(ord(substr($s,$i,1) ^ ($key >> 8)));
$key = (ord(substr($result,-1))+$key)*$c1 + $c2;
}
}
return $result;}
$s="testte";
$s1=encryp($s,815,1);
$result=bin2hex($s1);
echo "$s1
$result\n";
$s1= pack("H" . strlen($result),$result);
$result=encryp($s1,815,1);
echo "\n$result";
?></textarea>
<!-- -------------------------------------- -->
Was ist bei der PHP-Funktion falsch?
Andy