Can somebody help me with this error of mine? Im using sagepay module on my oscommerce website and i got this error: Warning: Division by zero in sage_pay_form.php on line 406. Here's the code.

function simpleXor($InString, $Key) {

    $KeyList = array();
    $output = "";

    for ($i=0; $i<strlen($Key); $i++) {
        $KeyList[$i] = ord(substr($Key, $i, 1));
    }

    for ($i=0; $i<strlen($InString); $i++) {
        $output .= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
    }

whats wrong with this?

$output .= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
有帮助吗?

解决方案

If that percent sign is the modulus operator, then the answer is obvious: strlen($key) must be zero.

Just in case you don't know, modulus is the operator that says "if z = x % y, then z equals the remainder that's left over when you divide x by y." So

z = x % y equals 1 if x = 5 and y = 2.

There's a division going on.

So if your $key is an empty string it'll have zero length. If it has zero length, you'll divide by zero to get the modulus. See the problem? You're assuming that string can never be empty, but your code found a case where it is. Check your assumptions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top