Verschlüsslungs Algorythmus

  • Hi,
    Ich habe im Internet einen kleine PHP Verschlüsslungs Algorythmus gefunden. Diesen habe ich halbwegs übersetzt bekommen nur bekomme ich etwas völlig anderes raus als bei der PHP Datei.

    Ich hoffe ihr könnt mir helfen.

    Hier ist der PHP Algorythmus

    Spoiler anzeigen


    und hier mein Versuch

    Spoiler anzeigen
    [autoit]


    #include <String.au3>
    #include <Array.au3>
    ; -1 Key Error

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "", Convert("12rtt3", "1234567hhhhh89zz"))

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Convert($str, $ky)
    If $ky = "" Then Return $str
    $ky = StringReplace($ky, Chr(32), '')
    If StringLen($ky) < 8 Then Return -1
    If StringLen($ky) < 32 Then
    $kl = StringLen($ky)
    Else
    $kl = 32
    EndIf
    Local $TmpArr[$kl]

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To $kl - 1
    $TmpArr[$i] = BitXOR(Ord(StringMid($ky, $i, 1)), 0x1F)
    Next
    ;~ _ArrayDisplay($TmpArr)
    $j = 0
    For $i = 0 To StringLen($str) - 1
    $e = Ord(StringMid($str, $i, 1))

    [/autoit] [autoit][/autoit] [autoit]

    If BitXOR($e, 0xE0) Then $str = StringReplaceCount($str, Chr($e ^ $TmpArr[$j]), $i)

    [/autoit] [autoit][/autoit] [autoit]

    $j = Mod(($j + 1), $kl)
    Next
    Return $str
    EndFunc ;==>Convert

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Ord($sStr)
    Return Asc(StringLeft($sStr, 1))
    EndFunc ;==>Ord

    [/autoit] [autoit][/autoit] [autoit]

    Func StringReplaceCount($sStr, $subString, $Index)
    $sStr = StringSplit($sStr, "")
    $sStr[$Index] = $subString
    Return _ArrayToString($sStr, "")
    EndFunc ;==>StringReplaceCount

    [/autoit] [autoit][/autoit] [autoit][/autoit]

    Schon mal danke für die Antworten !

    //Edit: Zum schluss müsste die Ausgabe beim Autoit Script so

    Code
    Yv3gf2jf+kvy9gj#p`8+qqlm3lp2q|n%hx|`qj}k

    aussehen

    • Offizieller Beitrag

    Also ich bekomme genau das heraus, was rauskommen soll ;-):

    Spoiler anzeigen
    [autoit]

    ConsoleWrite(convert('To be or not to be, that is the question', 'mysecretkey') & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    Func convert($text, $key = '')
    ;~ // return text unaltered if the key is blank
    ;~ if ($key == '') {
    ;~ return $text;
    ;~ }
    If $key = '' Then Return $text

    [/autoit] [autoit][/autoit] [autoit]

    ;~ // remove the spaces in the key
    ;~ $key = str_replace(' ', '', $key);
    ;~ if (strlen($key) < 8) {
    ;~ exit('key error');
    ;~ }
    $key = StringReplace($key, Chr(20), '')
    Local $key_len = StringLen($key)
    If $key_len < 8 Then Return SetError(0)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ // set key length to be no more than 32 characters
    ;~ $key_len = strlen($key);
    ;~ if ($key_len > 32) {
    ;~ $key_len = 32;
    ;~ }
    If $key_len > 32 Then $key = StringLeft($key, 32)

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $k = array(); // key array
    ;~ // fill key array with the bitwise AND of the ith key character and 0x1F
    ;~ for ($i = 0; $i < $key_len; ++$i) {
    ;~ $k[$i] = ord($key{$i}) & 0x1F;
    ;~ }
    Local $k = StringSplit($key, '', 2)
    For $i = 0 To UBound($k) -1
    $k[$i] = BitAND(Asc($k[$i]), 0x1F)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ;~ // perform encryption/decryption
    ;~ for ($i = 0, $j = 0; $i < strlen($text); ++$i) {
    ;~ $e = ord($text{$i});
    ;~ // if the bitwise AND of this character and 0xE0 is non-zero
    ;~ // set this character to the bitwise XOR of itself and the jth key element
    ;~ // else leave this character alone
    ;~ if ($e & 0xE0) {
    ;~ $text{$i} = chr($e ^ $k[$j]);
    ;~ }
    ;~ // increment j, but ensure that it does not exceed key_len-1
    ;~ $j = ($j + 1) % $key_len;
    ;~ }
    Local $aText = StringSplit($text, '', 2), $j = 0, $e, $outText = ''
    For $i = 0 To UBound($aText) -1
    $e = Asc($aText[$i])
    If BitAND($e, 0xE0) Then $aText[$i] = Chr(BitXOR($e, $k[$j]))
    $j = Mod($j+1, $key_len)
    $outText &= $aText[$i]
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ;~ return $text;
    ;~ }
    Return $outText
    EndFunc

    [/autoit]

    Ich habe deinen Code nicht im Detail geprüft - aber einen Fehler habe ich noch gesehen: Du hast "^" als Potenz interpretiert. In php ist das aber BitXOR.