String.fromCodeChar and codePointAt() js equivalent in php and js XOR vs PHP XOR

-3

I want to convert the bellow js function in php. with large int key.

function encodePassword(s, key) {
    var enc = "";
    var str = "";
    // make sure that `enter code here`input is string
    str = s.toString();
    for (var i = 0; i < s.length; i++) {
        // create block
        var a = s.charCodeAt(i);
        //var a = s.codePointAt(i);
        // bitwise XOR
        var b = a ^  key;
        enc += String.fromCharCode(b);
    }
    return enc;
}

I implemented as following

function decodePassword($password, $key) { 
$dec = ""; 
for ($i=0; $i < strlen($password); $i++) 
{ 
    $a = ord($password[$i]); 
    $b = ($a ^ $key); 
    /*& 0xffffffff; if ($b & 0x80000000) $b -= 0x100000000;*/ 
    $dec .= chr($b); 
} 
return $dec; 

}

$password = 'Welcome@321'; echo decodePassword($password, 9250715531967381);

and got the following result

��������զ��

javascript
php
asked on Stack Overflow Aug 22, 2019 by Subhash Chandra • edited Aug 22, 2019 by Subhash Chandra

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0