 |
[PHP]
อัพโหลดไฟล์แล้วมีเออเร่อครับ File 'c:\mysql\share\charsets\?.conf' not found (Errcode: 2) Character set '#18' is not a compiled character set and |
|
 |
|
|
 |
 |
|
อยากรู้มากๆเลยค่ะว่า output มันจะออกมายังไงใครรู้ช่วยบอกด้วยนะค่ะ ขอความกรุณาเถอะค่ะกลัวไม่จบอยู่
<?php
//coder: hsalinas
//i.e. simple http://localhost/rsa/rsa.php?p=47&q=71&e=79&mensaje=688
//i.e. wen ejemplo http://localhost/rsa/rsa.php?p=102639592829741105772054196573991675900716567808038066803341933521790711307779&q=106603488380168454820927220360012878679207958575989291522270608237193062808643&e=7&mensaje=101
echo "<pre>";
echo "----------------- RSA en php ----------------------\n";
$p = $_GET["p"];
$q = $_GET["q"];
$e = $_GET["e"];
$debug = $_GET["debug"];
$mensaje = $_GET["mensaje"];
if(!isset($debug)) $debug = false;
echo "p=".$p."\n";
echo "q=".$q."\n";
echo "mensaje=".$mensaje."\n";
echo "-------------------------- calculos --------------------\n";
$n = bcmul($p,$q);
echo "n=p*q=".$n."\n";
$f = bcmul( bcsub($p,"1"), bcsub($q,"1"));
echo "f=(p-1)(q-1)=".$f."\n";
if ($debug) echo "divisores de f son:\n"; //no activar para numeros grandes
if ($debug) print_r(divisores($f)); //no activar para numeros grandes
echo "e=".$e."\n";
if ($e <= 1 || $e >= $f) die("ERROR: e debe estar entre 1 y f");
if ($debug) if (!esCoprimo($e, $f)) die("ERROR: e debe ser coprimo de f y estar entre 1 y f"); //no activar para numeros grandes
echo "d=1/".$e."*(1 mod ".$f.")\n";
echo "lo anterior equivale a buscar k entero: \n";
echo "d=1/".$e."*(k*".$f." + 1)\n";
$d = moduloInverso($f, $e, $n);
echo "d=".$d."\n";
echo "-------------------------- encripto --------------------\n";
echo "c=m^e mod n\n";
$cifrado = encripto($mensaje, $e, $n);
echo "c=".$cifrado."\n";
echo "------------------------ desencripto -------------------\n";
echo "m'=c^d mod n\n";
$mensajeprima = desencripto($cifrado, $d, $n);
echo "m'=".$mensajeprima."\n";
echo "</pre>";
function moduloInverso($f, $e, $n)
{
//de = 1 (mod f)
//d = 1/e*(k*f + 1)
for ($k=1; $k<=$n; $k++)
{
$kf = bcmul($k,$f);
$kfmas1 = bcadd($kf, "1");
$d = bcdiv($kfmas1, $e, 100);
$entero = strtok($d, ".");
//echo "k=".$k."\nd=".$d."\nint(d)=".$entero."\n";
if (bccomp($d, $entero, 100 )==0 )
return $entero;
}
return -1;
}
function encripto($mensaje, $e, $n)
{
// c=m^e mod n;
return pow_mod($mensaje, $e, $n);
}
function desencripto($cifrado, $d, $n)
{
// m'=c^d mod n
return pow_mod($cifrado, $d, $n);
}
function divisores($numero)
{
for ($i=1; $i<=$numero; $i++)
{
if($numero%$i==0)
$retorno[]=$i;
}
return $retorno;
}
function esCoprimo($e, $f)
{
$a_divisores = divisores($f);
foreach($a_divisores as $divisor)
{
if($divisor == $e)
return false;
}
return true;
}
/* funcion robada de www.edsko.net/uploads/rsa.php */
function pow_mod($p, $q, $r)
{
// Extract powers of 2 from $q
$factors = array();
$div = $q;
$power_of_two = 0;
while(bccomp($div, "0") == 1)
{
$rem = bcmod($div, 2);
$div = bcdiv($div, 2);
if($rem) array_push($factors, $power_of_two);
$power_of_two++;
}
// Calculate partial results for each factor, using each partial result as a
// starting point for the next. This depends of the factors of two being
// generated in increasing order.
$partial_results = array();
$part_res = $p;
$idx = 0;
foreach($factors as $factor)
{
while($idx < $factor)
{
$part_res = bcpow($part_res, "2");
$part_res = bcmod($part_res, $r);
$idx++;
}
array_push($partial_results, $part_res);
}
// Calculate final result
$result = "1";
foreach($partial_results as $part_res)
{
$result = bcmul($result, $part_res);
$result = bcmod($result, $r);
}
return $result;
}
?>
อยากรู้มากๆเลยค่ะว่า output มันจะออกมายังไงใครรู้ช่วยบอกด้วยนะค่ะ ขอความกรุณาเถอะค่ะกลัวไม่จบอยู่
|
 |
 |
 |
 |
Date :
4 ส.ค. 2549 23:38:57 |
By :
หยดน้ำ |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมไม่ลอง Run ดูละครับ
|
 |
 |
 |
 |
Date :
5 ส.ค. 2549 09:02:23 |
By :
goragod |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถูกของคุณ goragod
ลอรันดูดิครับ 
|
 |
 |
 |
 |
Date :
6 ส.ค. 2549 09:14:43 |
By :
ผู้ไม่ประสงค์นาม |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|