Jump to content
Sign in to follow this  
Armand

AU3 ChrW->AscW Ascii Issues ?!

Recommended Posts

Armand

well, i have this JS code:

Loaded</br>
<script type="text/javascript">
    b64s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"';
    
    text = base64ToText('hTtqsTm"7PCR9sHBReqsbi_Ywrko4yLiKZFwNw88ZhbRuHHM41J33K9wvAFPcWJ_8CoOGm8EVWte_mRFiO_VSYtrVhp_WBwltRhtIN1k



rzU__MxqBeQiCku3G71pGlER_sfoXQr9RCfZ2xM49WuS1oxe6AnuH37hTzk7udxEN0P6q6Ob1wQjPEVDjqOxc"_ECmXkrzRvsj"l5UQPmeApOqtAZmKmebJLX8GtfN9t3D1x6n7creZyyVd');
    document.write("<br />"+text+" <br />"+text.length+"<br />"+"<br />")
    //for(n=0; n<text.length; n++)
    //  {
    //      c=text.charCodeAt(n);
    //      document.write("<br />"+c);
    //  }
    
    document.write("<br />"+"<br />"+enc(text));
    
    //for(JIJW=0,UqE=JIJW;JIJW<5;JIJW++){
    //  UqE = 2;
    //}
    
    function base64ToText(t)
    {
        var r=''; var m=0; var a=0; var c;

        for(n=0; n<t.length; n++)
        {
            c=b64s.indexOf(t.charAt(n));
            
            if(c >= 0)
            {
                if(m)
                    
                    r+=String.fromCharCode((c << (8-m))&255 | a);
                    
                    
                    a = c >> m;
                    //document.write(a);
                    //document.write(" [c="+c+" Shift="+(8-m)+"]<br />");
                    
                    m+=2;
                    if(m==8)
                        m=0;
            }
        }

        return r;
    }

    
    function enc(text){
        fQRco=new Array();
        IxH=223;

        for(oKsC=0;oKsC<IxH;oKsC++){
            fQRco[oKsC]=oKsC;
        }

        lTxoBV='2JtZU';

        for(    JIJW=0,
                UqE=JIJW,
                zjoTQq=fQRco;
                JIJW<IxH;
                JIJW++
            ){
            CHK = lTxoBV.charCodeAt(JIJW%lTxoBV.length);
            
            UqE=(CHK+zjoTQq[JIJW]+UqE)%IxH;
            Zlbt=zjoTQq[JIJW];
            zjoTQq[JIJW]=zjoTQq[UqE];
            zjoTQq[UqE]=Zlbt;
            zjoTQq[UqE]=zjoTQq[UqE]^5;
        }
        

        //document.write(zjoTQq);
        //document.write(" <br />");
        
        for(ptuHcb='',UqE=0,gphhIM=0;gphhIM<text.length;gphhIM++){
            SGn=gphhIM%IxH;
            UqE=(zjoTQq[SGn]+UqE)%IxH;
            lkkzT=zjoTQq[SGn];
            zjoTQq[SGn]=zjoTQq[UqE];
            zjoTQq[UqE]=lkkzT;
            
            ASC = text.charCodeAt(gphhIM);
            document.write(gphhIM+"=");
            document.write(ASC);
            document.write(" >"+text.charAt(gphhIM)+" <br />");
            
            ptuHcb+=String.fromCharCode((ASC^zjoTQq[(zjoTQq[SGn]+zjoTQq[UqE])%IxH]));
        }
        
    return ptuHcb;
    }
    

</script>

which i try to interprate into AU3, but it seems like AU3 has some compatibility issues:

#include "Array.au3"
;ConsoleWrite(AscW(Number(1)))
;Exit

$str = 'hTtqsTm"7PCR9sHBReqsbi_Ywrko4yLiKZFwNw88ZhbRuHHM41J33K9wvAFPcWJ_8CoOGm8EVWte_mRFiO_VSYtrVhp_WBwltRhtIN1krzU__MxqBeQiCku3G71pGlER_sfoXQr9RCfZ2xM49WuS1oxe6AnuH37hTzk7udxEN0P6q6Ob1wQjPEVDjqOxc"_ECmXkrzRvsj"l5UQPmeApOqtAZmKmebJLX8GtfN9t3D1x6n7creZyyVd'
$text = Base64ToTextSS($str)
ConsoleWrite($text&@CRLF&StringLen($text)&@CRLF&@CRLF&@CRLF)
;$textexp = StringRegExp($text, "(.)", 3)
;For $i = 0 To UBound($textexp)-1
;   ConsoleWrite(AscW($textexp[$i])&@CRLF)
;Next


;0=0, 1=1, 2=2 etc....
;CharCodeAt() = Asc()

Local $SSvar = 223
Dim $SSArray[$SSvar]

For $i = 0 To $SSvar-1
    $SSArray[$i] = $i
Next


Local $SSText = "2JtZU"
$n = 0

For $i = 0 To $SSvar-1
    $n = Mod((AscW(StringMid($SSText, Mod($i, StringLen($SSText))+1, 1))+$SSArray[$i]+$n), $SSvar)
    $Keep = $SSArray[$i]
    $SSArray[$i] = $SSArray[$n]
    $SSArray[$n] = $Keep
    $SSArray[$n] = BitXOR($SSArray[$n], 5)
Next

;_ArrayDisplay($SSArray)

$string = ""
$d = 0
$textexp = StringRegExp($text, "(?s:.)", 3)
For $i = 0 To UBound($textexp)-1
    $v = Mod($i,$SSvar)
    $d = Mod(($SSArray[$v]+$d),$SSvar)
    $Keep = $SSArray[$v]
    $SSArray[$v] = $SSArray[$d]
    $SSArray[$d] = $Keep
    
    $ASC = AscW(String($textexp[$i]))
    ConsoleWrite($i&"="&$ASC&" >"&$textexp[$i]&@CRLF)
    $string &= ChrW(BitXOR($ASC, $SSArray[Mod(($SSArray[$v]+$SSArray[$d]),$SSvar)]))
Next

ConsoleWrite(@CRLF&@CRLF&$string)

Func Base64ToTextSS($text)
    Local $b64s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"';
    $text = StringRegExpReplace($text, '[^0-9a-zA-Z_"]', '')
    $textexp = StringRegExp($text, "(?s:.)", 3)
    
    Local $r='', $m=0, $a=0, $c, $b
    For $n = 0 To UBound($textexp)-1
        $c = StringInStr($b64s, $textexp[$n], 1, 1)-1
        ;ConsoleWrite(@CRLF&$c&"="&$textexp[$n])
        
        if $c >= 0 Then
            If $c <> BitRotate($c, (8-$m), "B") Then 
                $b = BitRotate($c, (8-$m), "W")
            Else
                $b = 0
            EndIf
            
            $b = BitAND($b, 255)
            $b = BitOR($b, $a)
            
            ;If $b <> 0 Then
                $r &= ChrW($B)
                $r = StringReplace($r, ChrW(0), "")
            ;EndIf

            $a = BitShift($c, $m);
            ;ConsoleWrite($a&" [$c="&$c&" Shift="&(8-$m)&"]"&@CRLF)
            $m+=2
            If $m = 8 Then $m = 0

        EndIf
    Next
    Return $r
EndFunc

As you can see, both the AU3 and the JS codes are outputting the $ASC value of the second loop as it seems the only place where the too codes retrieve different results is at the:

#1:

AU3 -> $textexp[100] char retrieves 'AscW($textexp[100])=10'

JS -> text.charAt(zjoTQq[100]) char retrieves ' text.charCodeAt(zjoTQq[100])=26;'

#2

AU3 -> $textexp[181] char retrieves 'AscW($textexp[181])=1'

JS -> text.charAt(zjoTQq[181]) char retrieves ' text.charCodeAt(zjoTQq[181])=49;'

Any idea on how to fix it ?!

Edited by Armand

[u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×