示例#1
0
文件: index.php 项目: remco-pc/System
function encrypt($data = '', $encryption = '')
{
    if (empty($data)) {
        return;
    }
    switch (strtoupper($encryption)) {
        case 'MD5':
            $text = md5($data);
            break;
        case 'SHA1':
            $text = sha1($data);
            break;
        case 'CRC32':
            $text = crc32($data);
            break;
        case 'COMPLEX':
            //$text = complex($data);
            for ($i = 0; $i <= 100; $i++) {
                if (checkComplexString($data = complex($data)) === true) {
                    $text = $data;
                    break;
                }
            }
            break;
        default:
            $text = md5($data);
            break;
    }
    return $text;
}
示例#2
0
 public function testComplexHelperFunction()
 {
     $this->assertTrue(function_exists('complex'));
     $this->assertInstanceOf('Math\\Complex', complex(1, 1));
     $complex = complex(1, 2);
     $this->assertEquals($complex->getRealPart()->getValue(), 1);
     $this->assertEquals($complex->getImagPart()->getValue(), 2);
 }
示例#3
0
function julia_ppm($filename, $size, $depth, $zreal, $zimag)
{
    ## open the file
    if (file_exists($filename)) {
        unlink($filename);
    }
    $ppm = fopen($filename, "w");
    ## write ppm header
    ppm_write($ppm, "P3\n");
    ## write width and height
    ppm_write($ppm, $size . " " . $size . "\n");
    ## write max value
    ppm_write($ppm, $depth . "\n");
    ## write pixel values
    $z = complex($zreal, $zimag);
    $real_min = -1.2;
    $real_max = 1.2;
    $imag_min = -1.2;
    $delta = ($real_max - $real_min) / $size;
    for ($i = 0, $xreal = $real_min; $i < $size; $i++, $xreal = $xreal + $delta) {
        for ($j = 0, $ximag = $imag_min; $j < $size; $j++, $ximag = $ximag + $delta) {
            $count = 0;
            $x = complex($xreal, $ximag);
            while ($count < $depth && complex_abs($x) < 2.0) {
                $count++;
                $x = complex_add(complex_multiply($x, $x), $z);
            }
            if (complex_abs($x) <= 2.0) {
                ppm_write($ppm, "0 0 0\n");
            } else {
                $intensity = $count / $depth;
                if ($intensity > 0.001) {
                    ppm_write($ppm, round($depth - $depth * $intensity) . " " . round($depth - $depth * $intensity) . " " . $depth . "\n");
                }
            }
        }
    }
    fclose($ppm);
}