tags:

views:

252

answers:

3

9 = 2^X mod 11

What is X and how do you find X?

Its related to finding the plain text in RSA algorithm and I'm writing a C program for it.

A: 

I think that can be solved using modular arithmetic. Another way is calculating 9=2^X in F11 (Z/11Z), but that's part of modular arithmetic, too.

Another solution (where you'll find only ONE solution) is to solve the equation numerically, that's probably easier in a C program.

Johannes Weiß
+5  A: 

The answer is 6 + 10i for any integer i.

A simple way to get solutions for small moduli is to iterate over all values of x. You only need to check between 0 and 10 (= 11 - 1) to find the first solution, if any solution exists.

x = 0
while x < 50:
    if 9 == 2**x % 11:
         print x
    x += 1

Output:

6
16
26
36
46

Obviously this will take a long time if the modulus is large.

More information is on the Discrete Logarithm page. Note:

No efficient classical algorithm for computing general discrete logarithms logbg is known. The naive algorithm is to raise b to higher and higher powers k until the desired g is found; this is sometimes called trial multiplication. This algorithm requires running time linear in the size of the group G and thus exponential in the number of digits in the size of the group.

If it were easy to invert modular exponetiation, it wouldn't be a good cryptographic primitive.

Mark Byers
For this kind of arithmetic it is __much__ better to compute the powers by multiplying and doing the modulus at each step. This way the numbers stay small (always smaller than the modulus). This makes it possible to do the modular exponentation for very large exponents, which is exactly the case in cryptographic algorithms.
drhirsch
Yes, this is in fact exactly what the Wikipedia page suggests, under the name 'trial multiplication'. However it is still very slow. It is much better to use something like Baby Step, "Giant Step". You can read about it on wikipedia: http://en.wikipedia.org/wiki/Baby-step_giant-step
Mark Byers
+3  A: 

Obviously, sequence of 2^n mod 11 will be cyclical.

2^0 mod 11 = 1
2^1 mod 11 = 2
2^2 mod 11 = 4
2^3 mod 11 = 8
2^4 mod 11 = 5
2^5 mod 11 = 10
2^6 mod 11 = 9
2^7 mod 11 = 7
2^8 mod 11 = 3
2^9 mod 11 = 6
2^10 mod 11 = 1
2^11 mod 11 = 2

So, cycle length is 10.

2^n mod 11 = 9 for n=6+10*m where m is integer

yu_sha
I don't get this way...n=6+10*mhow you found 6 and 10 from nowhere? :\
from nowhere? "6": see the answer, 2^6 is a particular solution of the equation. "10": again, see the answer, the cycle repeats every 10 powers of 2.
Jason S
But you have to find the 6 first using bruteforce, so what's the use of that n=6+10*m if we got the value already. Sorry if I'm being an idiot. :\