-1

I have this function:

function dec($dec)
{
    $ans="";
    for($x=0; $x<strlen($dec);$x++)
    {
        $tempAscii = ord(substr($dec,$x,1)) - ($x+1)*2; //((int)dec[x] - (x+1)*2)
        while ($tempAscii <0) $tempAscii+=256;
        echo $tempAscii,", ";
        $ans = $ans . chr($tempAscii); 
    }
    return $ans;
}
echo "dec, ", dec($_GET['word']);

for example, those dec results are just fine:

input: as output: _o middle output: 95, 111
input: SHA256 output: QD;*+* middle output:  81, 68, 59, 42, 43, 42

But when I'm trying this input, I got something strange:

input: $@SHA256*!# output: " middle output: 34, 60, 77, 64, 55, 38, 39, 38, 24, 13, 13

I'm not sure if the reason I get this output is because I'm doing a mistake in my function, or there is other reason. Why I got " as the last result? thanks.

EDIT: I'm using firefox to see the results. EDIT: It seems that <is the problem. It seems that firefox take this as "smaller then"... How can I change it to be just > char without any meaning?

Moshe9362
  • 347
  • 1
  • 12

1 Answers1

0

Here is the solution: as @kyeiti mention before, the browser trying to interpret this string as code.

according to this question I solved this by using the command htmlspecialchars. So now my code is:

echo htmlspecialchars(enc($_GET['word']));

many thanks!

Community
  • 1
  • 1
Moshe9362
  • 347
  • 1
  • 12