Пример #1
0
<?php

/*
*/
if (!defined("WIKINI_VERSION")) {
    die("acc&egrave;s direct interdit");
}
if ($this->HasAccess("write") && $this->HasAccess("read")) {
    if (isset($_POST["submit"]) && $_POST["submit"] == 'Sauver') {
        require_once 'tools/hashcash/secret/wp-hashcash.lib';
        if ($_POST["hashcash_value"] != hashcash_field_value()) {
            $error = "Cette page n'a pas &eacute;t&eacute; enregistr&eacute;e car ce wiki pense que vous etes un robot.  Copiez-collez vos modifications et activez Javascript  !";
            $_POST["submit"] = '';
        }
    }
}
Пример #2
0
<?php

/*
*/
if (!defined("WIKINI_VERSION")) {
    die("acc&egrave;s direct interdit");
}
if ($this->HasAccess("write") && $this->HasAccess("read")) {
    if (isset($_POST["submit"]) && $_POST["submit"] == 'Sauver') {
        require_once 'tools/hashcash/secret/wp-hashcash.lib';
        if (!isset($_POST["hashcash_value"]) || $_POST["hashcash_value"] != hashcash_field_value()) {
            $error = '<div class="alert alert-danger"><a href="#" data-dismiss="alert" class="close">&times;</a>' . _t('HASHCASH_ERROR_PAGE_UNSAVED') . '</div>';
            $_POST["submit"] = '';
        }
    }
}
        /* Multiplication of square roots:
        	Time guarantee:  constant time */
    /* Multiplication of square roots:
    	Time guarantee:  constant time */
    case 2:
        $val = hashcash_field_value();
        $sqrt = floor(sqrt($val));
        $r = $val - $sqrt * $sqrt;
        $js .= "return {$sqrt} * {$sqrt} + {$r}; ";
        break;
        /* Sum of random numbers to the final value:
        	Time guarantee:  log(n) expected value */
    /* Sum of random numbers to the final value:
    	Time guarantee:  log(n) expected value */
    case 3:
        $val = hashcash_field_value();
        $js .= "return ";
        $i = 0;
        while ($val > 0) {
            if ($i++ > 0) {
                $js .= "+";
            }
            $temp = rand(1, $val);
            $val -= $temp;
            $js .= $temp;
        }
        $js .= ";";
        break;
}
$js .= "} {$function_name} ();";
// pack bytes
Пример #4
0
/**
 * Returns Javascript to compute field value.
 *
 * @param string $val_name Name of function
 * @return string
 */
function hashcash_field_value_js($val_name)
{
    $js = 'function ' . $val_name . '(){';
    $type = rand(0, 5);
    switch ($type) {
        /* Addition of n times of field value / n, + modulus */
        case 0:
            $eax = hashcash_random_string(rand(8, 10));
            $val = hashcash_field_value();
            $inc = rand(1, $val - 1);
            $n = floor($val / $inc);
            $r = $val % $inc;
            $js .= "var {$eax} = {$inc}; ";
            for ($i = 0; $i < $n - 1; $i++) {
                $js .= "{$eax} += {$inc}; ";
            }
            $js .= "{$eax} += {$r}; ";
            $js .= "return {$eax}; ";
            break;
            /* Conversion from binary */
        /* Conversion from binary */
        case 1:
            $eax = hashcash_random_string(rand(8, 10));
            $ebx = hashcash_random_string(rand(8, 10));
            $ecx = hashcash_random_string(rand(8, 10));
            $val = hashcash_field_value();
            $binval = strrev(base_convert($val, 10, 2));
            $js .= "var {$eax} = \"{$binval}\"; ";
            $js .= "var {$ebx} = 0; ";
            $js .= "var {$ecx} = 0; ";
            $js .= "while({$ecx} < {$eax}.length){ ";
            $js .= "if({$eax}.charAt({$ecx}) == \"1\") { ";
            $js .= "{$ebx} += Math.pow(2, {$ecx}); ";
            $js .= "} ";
            $js .= "{$ecx}++; ";
            $js .= "} ";
            $js .= "return {$ebx}; ";
            break;
            /* Multiplication of square roots */
        /* Multiplication of square roots */
        case 2:
            $val = hashcash_field_value();
            $sqrt = floor(sqrt($val));
            $r = $val - $sqrt * $sqrt;
            $js .= "return {$sqrt} * {$sqrt} + {$r}; ";
            break;
            /* Closest sum up to n */
        /* Closest sum up to n */
        case 3:
            $val = hashcash_field_value();
            $n = floor((sqrt(8 * $val + 1) - 1) / 2);
            $sum = $n * ($n + 1) / 2;
            $r = $val - $sum;
            $eax = hashcash_random_string(rand(8, 10));
            $js .= "var {$eax} = {$r}; ";
            for ($i = 0; $i <= $n; $i++) {
                $js .= "{$eax} += {$i}; ";
            }
            $js .= "return {$eax}; ";
            break;
            /* Closest sum up to n #2 */
        /* Closest sum up to n #2 */
        case 4:
            $val = hashcash_field_value();
            $n = floor((sqrt(8 * $val + 1) - 1) / 2);
            $sum = $n * ($n + 1) / 2;
            $r = $val - $sum;
            $js .= "return {$r} ";
            for ($i = 0; $i <= $n; $i++) {
                $js .= "+ {$i} ";
            }
            $js .= ";";
            break;
            /* Closest sum up to n #3 */
        /* Closest sum up to n #3 */
        case 5:
            $val = hashcash_field_value();
            $n = floor((sqrt(8 * $val + 1) - 1) / 2);
            $sum = $n * ($n + 1) / 2;
            $r = $val - $sum;
            $eax = hashcash_random_string(rand(8, 10));
            $js .= "var {$eax} = {$r}; var i; ";
            $js .= "for(i = 0; i <= {$n}; i++){ ";
            $js .= "{$eax} += i; ";
            $js .= "} ";
            $js .= "return {$eax}; ";
            break;
    }
    $js .= "} ";
    return $js;
}