Autor |
Beitrag |
Body3000
Hält's aus hier
Beiträge: 7
|
Verfasst: Do 28.06.07 19:50
Wir wollen folgende Delphi Funktion in PHP Code umschreiben und kommen da nicht weiter.
Wenn wir als passwort abc123 verwenden verschlüsselt die Delphi Funktion das in 62552F082091 und so soll es auch mit PHP gehen!
Hier der Delphi Code:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| const StartKey = 981; MultKey = 12674; AddKey = 35891; function Encrypt(const InString:string; StartKey,MultKey,AddKey:Integer): string; var I : Byte; v : byte; begin Result := ''; for I := 1 to Length(InString) do begin v := Byte(Byte(InString[I]) xor (StartKey shr 8)); Result := Result + IntToHex(v, 2); StartKey := (v + StartKey) * MultKey + AddKey; end; end; |
Und hier unser Lösungsansatz:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| require("inc/php/classes/BinaryUtils.php");
function passwordcrypt($clearpassword) { $StartKey = 981; //Start default key $MultKey = 12674; //Mult default key $AddKey = 35891; //Add default key $i=Math_BinaryUtils::decToBin(0); // ist bin $v=Math_BinaryUtils::decToBin(0); // ist bin $result='';
for ($i=0;$i<strlen($clearpassword);$i++) { $binvi=Math_BinaryUtils::littleEndianToBin($clearpassword{$i}); $binStartKey=Math_BinaryUtils::decToBin($StartKey);
//$v = $binvi ^ ($binStartKey>>8); $v = $clearpassword{$i} ^ ($StartKey>>8);
$result = $result + dechex($v) . ""; $result;
$StartKey=($v + $StartKey) * $MultKey + $AddKey .""; // $StartKey = dechex(($v + $binStartKey) * $MultKey + $AddKey); } return($StartKey); }
// $StartKey2 = 981; // echo $StartKey2>>3;
echo passwordcrypt("abc123"); |
Moderiert von Christian S.: Delphi- und Code-Tags hinzugefügt
|
|
Heiko
Beiträge: 3169
Erhaltene Danke: 11
|
Verfasst: Fr 29.06.07 19:53
Was ich bei deinem PHP-code noch nicht ganz verstehe: Wofür wandelst du dec in bin um? Braucht das ">>" von php das etwa so? Ansonsten würde ich da keinen Sinn sehen (habe bisher noch keine binäroperatoren bei php gebraucht )
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: Fr 29.06.07 21:17
Strings werden in PHP mit . verbunden ... Nimm aber am besten gleich $result .= 'neuer Text'; ...
Außerdem fügst Du in PHP was anderes zusammen als unter Delphi ...
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Body3000
Hält's aus hier
Beiträge: 7
|
Verfasst: So 01.07.07 11:48
Kannst Du mir dann da ein konkreten Lösungsansatz geben, ich komm so nicht weiter.
Vielen Dank!
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: So 01.07.07 11:55
Body3000 hat folgendes geschrieben: | Und hier unser Lösungsansatz:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33:
| require("inc/php/classes/BinaryUtils.php");
function passwordcrypt($clearpassword) { $StartKey = 981; //Start default key $MultKey = 12674; //Mult default key $AddKey = 35891; //Add default key $i=Math_BinaryUtils::decToBin(0); // ist bin $v=Math_BinaryUtils::decToBin(0); // ist bin $result='';
for ($i=0;$i<strlen($clearpassword);$i++) { $binvi=Math_BinaryUtils::littleEndianToBin($clearpassword{$i}); $binStartKey=Math_BinaryUtils::decToBin($StartKey);
//$v = $binvi ^ ($binStartKey>>8); $v = $clearpassword{$i} ^ ($StartKey>>8);
$result = $result + dechex($v) . ""; //Das sieht ja schon falsch aus!!! $result; //Was soll das bitte schön tun???
$StartKey=($v + $StartKey) * $MultKey + $AddKey .""; //Aha ... // $StartKey = dechex(($v + $binStartKey) * $MultKey + $AddKey); } return($StartKey); }
// $StartKey2 = 981; // echo $StartKey2>>3;
echo passwordcrypt("abc123"); | |
Außerdem ist return keine Funktion, sondern ein Keyword ... Im Normalfall kommen da keine Klammern drum ... Selbst wenn PHP keine Typen kennt, wird sehr wohl noch zwischen Integers und Strings unterschieden ... "2" + "3" ergibt 5, "2"."3" ergibt "23" ... Kleiner aber feiner Unterschied ... RTFM. BenBE.
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Body3000
Hält's aus hier
Beiträge: 7
|
Verfasst: So 01.07.07 12:16
Vielen Dank,
aber leider hilft auch dieser Lösungsansatz nicht weiter ....
Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| <?php require("inc/php/classes/BinaryUtils.php");
function passwordcrypt($clearpassword) { $StartKey = 981; //Start default key $MultKey = 12674; //Mult default key $AddKey = 35891; //Add default key $i=Math_BinaryUtils::decToBin(0); // ist bin $v=Math_BinaryUtils::decToBin(0); // ist bin $result='';
for ($i=0;$i<strlen($clearpassword);$i++) { $binvi=Math_BinaryUtils::littleEndianToBin($clearpassword{$i}); $binStartKey=Math_BinaryUtils::decToBin($StartKey);
$v = $clearpassword{$i} ^ ($StartKey>>8);
$result = $result + dechex($v);
$StartKey=($v + $StartKey) * $MultKey + $AddKey .""; //Aha ... } return $StartKey; }
echo passwordcrypt("abc123"); ?> |
Ich erhalte da folgenden Rückgabewert: 4.1062132246E+27
Zurückgeliefert werden soll jedoch: 62552F082091
Moderiert von Christian S.: Code-Tags hinzugefügt
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: So 01.07.07 12:42
Da markiert man explizit die Zeilen, wo Fehler sind und korrigiert werden sie trotzdem nicht ...
Ich wiederhole mich bzgl. der Fehlerursache jetzt nicht ... Lese meinen vorigen Post aufmerksam, dann wirst Du finden, was ich meine ...
Zeilen 21 und 23. Weiterhin sollte man, wenn man Bytes will, diese auch erzwingen wenn man größere Datentypen nutzt ...
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Body3000
Hält's aus hier
Beiträge: 7
|
Verfasst: So 01.07.07 13:15
Hatte da etwas übersehen, aber trotzdem ändert das nichts an der Tatsache das es noch immer nicht das gewünschte Ergebnis ausgibt.
Hier nochmal der modifizierte PHP-Code in der Hoffnung das ich hier Hilfe erhalte, da das Problem dringend gelöst werden muss.
C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| <?php require("inc/php/classes/BinaryUtils.php");
function passwordcrypt($clearpassword) { $StartKey = 981; $MultKey = 12674; $AddKey = 35891; $i=Math_BinaryUtils::decToBin(0); $v=Math_BinaryUtils::decToBin(0); $result='';
for ($i=0;$i<strlen($clearpassword);$i++) { $binvi=Math_BinaryUtils::littleEndianToBin($clearpassword{$i}); $binStartKey=Math_BinaryUtils::decToBin($StartKey);
$v = $clearpassword{$i} ^ ($StartKey>>8);
$result .= dechex($v);
$StartKey=($v + $StartKey) * $MultKey + $AddKey; } return $result; }
echo passwordcrypt("abc123"); ?> |
Rückgabewert: 3bed7d24b03d248823
Moderiert von Christian S.: C#-Tags hinzugefügt
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: So 01.07.07 13:28
k, Sache von 5 Minuten, die Fehler zu fixen ... C#-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
| function passwordcrypt($clearpassword) { $StartKey = 981; $MultKey = 12674; $AddKey = 35891; $i = 0; $v = 0; $result = '';
for ($i = 0;$i < strlen($clearpassword);$i++) { $binvi = ord($clearpassword{$i}); $binStartKey = ord($StartKey);
$v = ($binvi ^ ($StartKey >> 8)) & 0xFF;
$result .= substr("00" . dechex($v),-2);
$StartKey = (($v + $StartKey) * $MultKey + $AddKey) & 0xFFFFFFFF; } return strtoupper($result); }
echo passwordcrypt("abc123"); | P.S.: Wenn Du Code\Tags nutzten würdest, wäre das wesentlich übersichtlicher ... P.P.S.: Mich wundert, dass dieser Source mit Delphi bei euch ohne Exceptions läuft. Wenn man da aus Versehen mal die BEreichs-\Überlaufprüfung aktiviert, wirft der mit Exceptions nur so um sich ... Und dass PHP da rummeckert, was von Haus aus mit Int64 arbeitet, sollte klar sein ... P.P.P.S.: Man sollte in einer Funktion auch das Zurückgeben, was man als Ergebnis haben möchte
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
Body3000
Hält's aus hier
Beiträge: 7
|
Verfasst: So 01.07.07 13:37
Vielen Dank,
ich denke Du bist da einige Ebenen weiter als ich.
Da kann man viel von lernen
Grüße
Boris
|
|
BenBE
Beiträge: 8721
Erhaltene Danke: 191
Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
|
Verfasst: So 01.07.07 13:39
Body3000 hat folgendes geschrieben: | Vielen Dank,
ich denke Du bist da einige Ebenen weiter als ich.
Da kann man viel von lernen
Grüße
Boris |
Jain ... ich hab nur mal für PHP nen Debugger gestartet ... Siehe www.waterproof.fr ... Den gibt's für privaten Einsatz kostenlos (auf Anfrage dort) ... Und während des Debuggens ist mir aufgefallen, dass Du da keine Begrenzung des Zahlenbereichs drin hattest...
_________________ Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
|
|
|