edited by
318 views
1 votes
1 votes
Consider the $\text{fast  square}$ and $\text{multiply algorithm}$ to calculate $x^y \text{ mod } N$ as given below, where $x, \: y,\: N$ are positive integers and $1 \leq x, y < N$.

Input: $x, \:y, \:N$

Output: $x^y \: \text{ mod } N$

1. $z = y, u = 1, v = x;$

2. while $z > 0$ do

3. if $z \equiv \: 1$ mod $2$ then

4. $u = uv \text{ mod } N$;

end

5. $v = v^2 \text{ mod } N; \:  z = \lfloor \frac{z}{2} \rfloor$

end

6. return $u$.

What is the time complexity of the algorithm in terms of $N$? [Note that $N$ can be a very large integer, e.g., more than $512$ bits. Assume that the time complexity of modular multiplication is $O(log^2 \: N)$, when the positive integers involved are less than $N$.]
edited by

Please log in or register to answer this question.

Related questions

1 votes
1 votes
0 answers
1
go_editor asked Jun 1, 2016
523 views
A connected, simple, undirected planar graph $G(V, E)$ is given where $V$ denotes the set of vertices and E denotes the set of edges. In $V$, there is a designated source...