|
użytkowników online: 58
|
OPINIE UŻYTKOWNIKÓW
|
Porady zamieszczone tutaj przez Darka są pomocne w wielu chwilach. Wielokrotnie tworząc jakiś złożony serwis korzystam z tych porad. Można by tworzyć samemu te skrypty, ale tak naprawdę czy nie lepiej jest wziąć skrypt z tej strony i zmodyfikowac go dla swoich potrzeb? Wprawdzie możemy taki skrypt napisać sami, ale po co, skoro stracimy czas na coś, co ktoś juz napisał, przetestował i może zagwarantować, że działa poprawnie. Któryś raz z rzędu opłacam abonament i nie raz jeszcze opłacę. Kawał dobrej roboty i ogrom wiedzy w jednym miejscu.
Piotr Karamański Design Studio
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
bcpowmod (PHP 5) bcpowmod --
Raise an arbitrary precision number to another, reduced by a specified modulus
Descriptionstring bcpowmod ( string x, string y, string modulus [, int scale] )
Use the fast-exponentiation method to raise x
to the power y with respect to the modulus
modulus. The optional
scale can be used to set the number of
digits after the decimal place in the result.
Notatka:
Because this method uses the modulus operation, non-natural numbers
may give unexpected results. A natural number is any positive
non-zero integer.
Przykłady
The following two statements are functionally identical. The
bcpowmod() version however, executes in
less time and can accept larger parameters.
User Contributed NotesJason at v7studios d o t com
10-Jan-2006 04:37
Do not use ewilde aht bsmdevelopment dawt com's function.
Look at the example... don't use an unnecessary while loop...
<?php
$a = bcpowmod($x, $y, $mod);
$b = bcmod(bcpow($x, $y), $mod);
?>
Here is your answer:
bcmod(bcpow($x, $y), $mod);
ewilde aht bsmdevelopment dawt com
28-Sep-2005 06:46
Versions of PHP prior to 5 do not have bcpowmod in their repertoire. This routine simulates this function using bcdiv, bcmod and bcmul. It is useful to have bcpowmod available because it is commonly used to implement the RSA algorithm.
The function bcpowmod(v, e, m) is supposedly equivalent to bcmod(bcpow(v, e), m). However, for the large numbers used as keys in the RSA algorithm, the bcpow function generates a number so big as to overflow it. For any exponent greater than a few tens of thousands, bcpow overflows and returns 1.
This routine will iterate through a loop squaring the result, modulo the modulus, for every one-bit in the exponent. The exponent is shifted right by one bit for each iteration. When it has been reduced to zero, the calculation ends.
This method may be slower than bcpowmod but at least it works.
function PowModSim($Value, $Exponent, $Modulus)
{
// Check if simulation is even necessary.
if (function_exists("bcpowmod"))
return (bcpowmod($Value, $Exponent, $Modulus));
// Loop until the exponent is reduced to zero.
$Result = "1";
while (TRUE)
{
if (bcmod($Exponent, 2) == "1")
$Result = bcmod(bcmul($Result, $Value), $Modulus);
if (($Exponent = bcdiv($Exponent, 2)) == "0") break;
$Value = bcmod(bcmul($Value, $Value), $Modulus);
}
return ($Result);
}
|