0

Given that I know the value of $e$ and $F$. How to determine an unique integer value for $d$ in such a way that the reminder of the division of $(d \cdot e)$ per $F$ is equal to one?

$(d \cdot e) \pmod{F} \equiv 1$

I'm doing this to implement a small version of the RSA algorithm as described here. Thanks in advance.

Edit: Trying one by one values of $d$ and verifying is the equation matches is out of hand, the algorithm would be very slow. I guess that there must have some math trick to do this.

iadvd
  • 8,875
Fnr
  • 103

1 Answers1

1

For your example you have $p=3, q=1, n = pq = 33$, so $\phi(n) = (p-1)(q-1) = 20$.

Then $e = 7$ was chosen, which is indeed coprime with $n$.

Then compute the greatest common divisor as done in this answer, and the link therein.

So write $$ \begin{array}{rrr} 20 & 1 & 0\\ 7 & 0 & 1\\ 6 & 1 & -2\\ 1 & -1 & 3 \end{array}$$

where the row 3 = row 1 - 2* row 2, because 7 fits two times into 20, with remainder 6. Row 4 = row 3 - row 2, because 6 fits into 7 once with remainder 1.

For any row $a \text{ } b \text{ } c$ we have that $a = 20b + 7c$, which is true for the first two rows trivially and gets preserved by the row multiplications and subtractions.

So the last row gives us $$1 = -1 \cdot 20 + 3 \cdot 7$$

(which can easily be verified). Taking this equation modulo $\phi(n) = 20$, the left term is just $0$ (vanishes), as all multiples of $20$, and we are left with

$$1 \equiv 3 \cdot 7 \pmod{20}$$

showing that 3 and 7 are each other's inverse modulo 20.

In this case the numbers are small enough to do it without fancy algorithms, but for numbers of 300 or more digits (as is for practical RSA) having a (very) fast algorithm is a good thing.

Henno Brandsma
  • 242,131