0

We have hypothetical equation: $2^{b} \% k = z$.

Assume that we know $z$, $b$ and $k$. So everything! We want to know only if the above equation is true.

I do not want to use the exponentiation modulo - I am looking for some faster method. I do not need to know the exact value of $ 2 ^ {b} \% k $. I just want to know if it is $ z $.

It can be done without trivial exponent modulo?


Edit:

My mistake: $b = k$:

$2^{b} \% b = z$.

Bill Dubuque
  • 282,220
Aurelio
  • 499
  • Write down $2^b$ in binary, subtract $z$, divide by $k$. – André Nicolas Jul 04 '16 at 15:10
  • @Dietrich Burde: I know https://en.wikipedia.org/wiki/Modular_exponentiation. I do not need, however, the exact value. I want to know is whether the outcome of the power modulo is $z$. Possible answer: "Yes" or "No". – Aurelio Jul 04 '16 at 15:13
  • But $z$ is the exact value. So we just want to know the result of, say, $2^{176}\bmod 177$ (see the link). It is $z=4$, and this is the exact value (modulo $177$). – Dietrich Burde Jul 04 '16 at 15:22
  • When you write $2^b% k$, do you mean $\frac{2^b}{100}k$ or $2^b\bmod k$? – hmakholm left over Monica Jul 04 '16 at 15:22
  • @André Nicolas: Can you say more? I do not understand. – Aurelio Jul 04 '16 at 15:24
  • @Henning Makholm: $2^{b} mod k$ – Aurelio Jul 04 '16 at 15:25
  • @Dietrich Burde: There is no faster way? – Aurelio Jul 04 '16 at 15:27
  • 1
    The fastest way to know whether $2^b\bmod k$ is $z$ is to compute it and compare the result to $z$. Your comments seem to suggest that you're not fully aware how fast ways there are to compute $2^b\bmod k$ -- in particular, it is not necessary to calculate $2^b$ explicitly just to find its residue modulo $k$. – hmakholm left over Monica Jul 04 '16 at 15:27
  • I still think you are done with repeated squaring, see the link above. This is quite fast. – Dietrich Burde Jul 04 '16 at 15:30
  • @Henning Makholm: I know this method. But I want to calculate, for example, for $b = 2^{50000000}$ and $k = 2^{50000000}$. I can not do it so quickly. I just noticed my mistake (first post): $b = k$. – Aurelio Jul 04 '16 at 15:35
  • @MarekWolny: When $b$ and $k$ are the same power of $2$ (or in general when $k=2^M$ and $b>M$), then $2^b\bmod k=0$. Very fast to compute. – hmakholm left over Monica Jul 04 '16 at 15:40
  • @MarekWolny: My suggestion does nothing useful, to do the division fast we still need binary method of exponentiaition. – André Nicolas Jul 04 '16 at 15:40
  • And if you really have a 6-megabyte arbitrary bignum for $b=k$ and another number of the same size as $z$, then I think it's reasonable that you have to spend some effort getting knowledge out of inputs of that size. – hmakholm left over Monica Jul 04 '16 at 15:45
  • @Henning Makholm: It was just an example of the size. And in the case where $b = 2 ^ {50000000} -1$ and $k = 2 ^ {50000000} -1$? – Aurelio Jul 04 '16 at 15:45

1 Answers1

1

The fastest general method to know whether $2^b\bmod k$ is $z$ is to compute it and compare the result to $z$. Your comments seem to suggest that you're not fully aware how fast repeated squaring is for computing $2^b\bmod k$ -- in particular, it is not necessary to calculate $2^b$ explicitly just to find its residue modulo $k$.

Of course, if $b$ is larger than $k$ and you know the factorization of $k$, it may pay to reduce $n$ modulo $\lambda(k)$ or $\phi(k)$ first -- but that, too, is a shortcut for computing $2^b\bmod k$, not something that benefits from knowing your $z$.

There's one situation where you can squeeze a small amount of additional performance out of knowing $z$, namely if after reducing $b$ modulo $\lambda(k)$ you find out that $\lambda(k)-b$ is small compared to $b$. In that case you can rewrite $$ 2^b \equiv z \pmod k $$ to $$ 1 \equiv 2^{\lambda(k)-b} z \pmod k $$ But if the initial $b$ is arbitrary, it will only be in a very small fraction of cases that this actually save you any significant exponentiation work.