XOR encryption Javascript and PHP fails with some keys -


i'm trying crypt/decrypt $session_key string, generated random function, in php , javascript. works not strings. $session_key, in example, result it's different. can see result opening browser console.

<?php  function xor_this($str, $key) {     $result = '';     ($i = 0; $i < strlen($str); $i++) {         $tmp = $str[$i];         ($j = 0; $j < strlen($key); $j++) {             $tmp = chr(ord($tmp) ^ ord($key[$j]));         }         $result .= $tmp;     }     return $result; }  #session_key generated substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"), 0, 40) $session_key = 'h9pyae6kcex5g7081snjcfbpvfux3brtmdydwwhq'; $password = '9b06a9342b5ac4a825088a0f0c2a2e7cc091393f';   echo xor_this($session_key, $password);  ?>  <html>     <script>          function xor_this(str,key)         {             var xor = "";             (var = 0; < str.length; ++i) {                 tmp = str[i];                 for(var j = 0; j < key.length; ++j) {                     tmp = string.fromcharcode(tmp.charcodeat(0) ^ key.charcodeat(j));                 }                 xor += tmp;             }             return xor;         }          var session_key = '<?php echo $session_key?>';         var password = '<?php echo $password?>';         console.log(xor_this(session_key,password));      </script> </html> 

with given $session_key result same php , javascript.

php produces: g6_vnj9dljw:h8?7>\aelimyizw<m]{bkvkxxg~

javascript produces: g6_vnj9dljw:h8?7>\aelimyizw<m]{bkvkxxg~

note < start new html tag , browser won't show rest of output on page. have use "view source" see it, or make program call htmlspecialchars before outputting result.

this isn't of encryption way: long password doesn't give protection since of chars xored always. example $password=chr(15) gives same results current password.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -