var b=new Array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);
var p=new Array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);
function c(b,p) {
a='';s=String.fromCharCode;
for(i=0;i<b.length;i++) {if(p[i])a=s(b[i])+a;else a+=s(b[i]);}
return a;
}
I am trying to convert the above JavaScript code to PHP, but because in some ways it is compressed to make it more confusing, I'm having great difficulty. Your help is greatly appreciated!
UPDATE: This is what I've tried:
<?php
$b=array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);
$p=array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);
$a='';
class String {
public static function fromCharCode() {
return array_reduce(func_get_args(),function($d,$e){$d.=chr($e);return $d;});
}
}
for($i=0;$i<b.length;$i++) {if($p[$i])$a=String::fromCharCode($b[$i]) . $a;else $a+=String::fromCharCode($b[$i]);}
echo $a; ?>
It returns blank.
How do I convert this simple Javascript into PHP?
Not tested. Just a literal translation
function c($b, $p){
$a="";
for ($i=0;$i<strlen($b);$i++){
if ($p[$i]) $a=chr($b[$i]).$a; else $a.=chr($b[$i]);
}
return $a;
}
In PHP
function c($b,$p){
$a = '';
$s = chr();
for($i=0;$i<strlen($b);$i++){
if($p[$i]){
$a = chr($b[$i]).$a;
} else {
$a .= chr($b[$i]);
}
}
return $a;
}
Note: you ought to give your variables more descriptive names
Another approach I used for this kind of hack was to dynamically write javascript script by PHP but echoing it out via http header with content-type identifier. See below as an example:
index.html:
<script type="text/javascript" src="js.php"></script>
js.php
<?php
$js = <<<JS
///BEGIN JS SCRIPT //
var b=new Array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98);
var p=new Array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1);
function c(b,p) {
a='';
s=String.fromCharCode;
for(i=0;i<b.length;i++) {if(p[i])a=s(b[i])+a;else a+=s(b[i]);}
return a;
}
/// END JS SCRIPT //
JS;
header("Content-type: text/javascript");
echo $js;
exit();
?>
One setback I found about this approach is that the script can't be cached if you want to re-access to these variables in later lines of scripts from your html. But, it serves as a great benefit for some implementation of my work "behind the scene".
The best way to do it it's to use chr .
chr — Return a specific character
$b = array(102,50,57,101,52,55,53,54,49,57,55,97,100,55,52,99,48,56,53,100,55,97,98,53,101,101,102,100,49,49,101,54,50,97,100,48,97,101,49,52,38,104,61,50,52,61,56,55,101,99,102,110,111,51,55,78,109,114,111,57,101,54,102,51,101,38,101,56,54,56,53,53,54,54,53,51,56,102,57,54,52,61,100,101,50,57,49,99,105,50,102,95,116,54,102,101,115,51,105,100,48,108,116,57,105,104,54,63,48,112,104,112,48,46,121,116,110,117,111,98); $p = array(0,0,0,0,1,0,1,1,1,0,0,1,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,1,0,0,0,0,0,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,0,0,0,1,0,0,1,0,1,0,0,1,1,1,1,0,1,0,0,1,0,0,1,1,0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,1,0,0,1,1,0,1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1); function c($b,$p) { $a=''; for($i=0;$i<count($b);$i++){ if($p[$i]){ $a=chr($b[$i]) . $a; }else{ $a.=chr($b[$i]); } } return $a; } echo(c($b,$p));
OUTPUT
bounty.php?hitlist_id=9366558&formNonce=e0d2fe5b7d80c47a1654f29e797d5aed11e6aa14&h=2487f379e63ee6858f64e291c2f6fe3d09600
Both examples in JS and PHP same output.
working example php: example
working example js: example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.