commands → log

log(A,B)
log(A,B,0)
log(A,B,P)

The log command computes the base-B logarithm of a numeric value A. If a third argument P is given it is the modulus and we solve A = B^X mod P. If P is zero then log computes the integer floor of log(A,B).

Examples

log(10,10);
	1.

log(8,2,0);
	3

log(10,3,0);
	2

# solve 5 = 4^X mod 11
logmod(5,4,11);
	2

(4^2) % 11;
	5

Algorithm

To compute log(a) to the base b, we compute the quotient ln(a)/ln(b). The Pohlig-Hellman algorithm and Pollard's rho algorithm are used to compute discrete logarithms.

References

Gullberg, Jan. Mathematics: From the Birth of Numbers. Norton, 1996.
Link to Handbook of Applied Cryptography Cohen, Henri. A Course in Computational Algebraic Number Theory. Springer, 1993. Koblitz, Neal. A Course in Number Theory and Cryptography. Springer, 1998.