PDA

Просмотр полной версии : Переписать функцию с JavaScript на PHP за $$$


ttt0z
18.11.2008, 11:33
function convertToHex(num) {
var hex = '';
for (i=0;i<num.length;i++) {
if (num.charCodeAt(i).toString(16).toUpperCase().leng th < 2) {
hex += "&#x0" + num.charCodeAt(i).toString(16).toUpperCase() + ";";
} else {
hex += "&#x" + num.charCodeAt(i).toString(16).toUpperCase() + ";";
}
}
return hex;
}

для проверки из слова hello должно получиться
&#x68;&#x65;&#x6C;&#x6C;&#x6F;

bombeg
18.11.2008, 11:43
function encode($word)
{
$result = '';
for($i = 0, $size = strlen($word);$i < $size; $i++)
{
$result .= '&#x' . strtoupper(bin2hex($word[$i])) . ';';
}

return $result;
}
echo encode('hello');

ttt0z
18.11.2008, 12:10
bombeg спасибо можешь еще помочь с кодом:



надо что бы полоучилось примерно:
javascript:alert('XSS')

это Long UTF-8 Unicode encoding without semicolons
This is also useful against people who decode against strings like $tmp_string =~ s/.*\&#(\d+);.*/$1/;

TomskDiver
18.11.2008, 12:13
получилось из чего? как я понимаю ты что-то для xss делаешь?

bombeg
18.11.2008, 12:17
function encode($word)
{
$result = '';
for($i = 0, $size = strlen($word);$i < $size; $i++)
{
$result .= '�';
$result .= (ord($word[$i]) < 100) ? '0' .ord($word[$i]) : ord($word[$i]);
}

return $result;
}
echo encode("javascript:alert('XSS')");

ttt0z
18.11.2008, 12:20
bombeg спасибо большое!

bombeg
18.11.2008, 14:10
$1 :D