Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem of discrete logarithm calculation using Python code

I have a set of logarithm which are L1, L2 and L3 which I have retrieved it from the paper An Ultra-secure Router-to-router Spontaneous Key Exchange System (2015), here. The aim of this paper is to securely share key between Alice and Bob. For example, Alice sent K = 46 to Bob. Bob received the key from Alice. Key can be represented as:

enter image description here

The key needs to be shared using three stage process. L1: Alice to Bob. L2: Bob to Alice. L3: Alice to Bob.The equations are:

enter image description here

enter image description here

enter image description here

Bob can evaluate the key using: enter image description here

This is the result for the equations: enter image description here

Given the value of alpha = 5, x = 15 and p = 97. After I implement it in Python, I got the wrong result, which is not same in the result in the table:

a=5
x=15
p=97
i1=0.958478
i2=4.238835

L1=a**(x+i1)%p
L2=a**(x+i1+i2)%p
L3=a**(x+i2)%p
K=L3*(a**(-i2))

print ("L1",L1)
print ("L2",L2)
print ("L3",L3)
print ("K",K)

Which produce this result:

L1 55.596893310546875
L2 2.15625
L3 68.87890625
K 0.07503566293789979

Another problem is I tried to calculate it manually but the result is still not same with the result in the table. I hope that anyone may help me. Thank you.

like image 315
Afir Avatar asked Jul 21 '19 08:07

Afir


People also ask

How can you explain the discrete logarithm problem?

The discrete logarithm problem is defined as: given a group G, a generator g of the group and an element h of G, to find the discrete logarithm to the base g of h in the group G. Discrete logarithm problem is not always hard. The hardness of finding discrete logarithms depends on the groups.

How hard is the discrete logarithm problem?

The discrete logarithm problem is considered to be computationally intractable. That is, no efficient classical algorithm is known for computing discrete logarithms in general. A general algorithm for computing logb a in finite groups G is to raise b to larger and larger powers k until the desired a is found.

How is discrete logarithm evaluated for a number?

of k by evaluating the discrete logarithm k = loga r, and then compute m ≡ t · b−k (mod p), or she could compute Bob's value of d by evaluating d = loga b and then compute m the same way Bob does.


1 Answers

A math-savvy friend of mine helped me figure out what went wrong. The answers that you got are correct. The issue is with the values that authors have given for i1 and i2.

A single additional decimal number completely changes the result of the mod p operation in this part:

L1 = a**(x+i1)%p In the case of i1 being equal to 0.958478, the output is: 55.596893310546875

Now, if you add even a single additional 1 to the end of the value for i1, resulting in an i1 of 0.9584781, the output of the same equation becomes a completely different number: 37.163330078125

If you compare the algorithm to determine that K = L3*a**(-i2), using the given i2 of 4.238835, you will also quickly find that the result is not equal to 46. The initial value of K, as calculated with the algorithm (a**x)%p, was 46, so that's what the above algorithm should have evaluated to. Instead, the result of this equation with the given values is 0.05102662974.

My friend came up with a theory based on the fact that the authors said they were using Matlab. Matlab has a feature that allows the user to limit to what decimal place numbers are displayed. The decimal numbers still behave according to their actual value, but their representation on screen is truncated to the specified decimal place. For most operations, this is totally fine and would have a negligible impact on the results of the calculations. However, when performing a modulus operation, a single 1, even in the least-significant decimal place of the number, can alter the entire number.

Thus we conject that the actual i1 and i2 values were truncated by their display settings in Matlab. This wouldn't alter the algorithm's truthiness and also wouldn't prevent it from evaluating to the correct value of variable K at the end of the operation. All the results of having used the full decimal values of i1 and i2 would have been displayed. However, it would also make the entire process impossible to reproduce for someone using the same numbers that Matlab had displayed to our authors at the time of calculation.

like image 110
andrewfellenz Avatar answered Sep 22 '22 02:09

andrewfellenz