0

I am learning RSA cryptography. The part I am stuck on is understanding how k and the public exponent $e$ is selected.

Given the formulas;

Decrypting: $c^d \bmod N = (m^e)^d \bmod N$ Which is equal to m the message

Encrypting: $m^e \bmod N = c$

My question is when generating the private exponent how do we find what the public exponent should be and what k should be in the formula

$$d = (1 + k*\varphi(N))/e$$

I understand it has something to do with the inverse of modules but I don t get the math behind it.

kelalaka
  • 48,443
  • 11
  • 116
  • 196
User
  • 115
  • 3

1 Answers1

1

You apply the extended Euclidean algorithm to $e$ and $\phi(N)$ (which have to have gcd equal to $1$) and we get $x,y \in \mathbb{Z}$ such that

$$xe + y\phi(N) = 1$$

The $x$ (taken modulo $\phi(N)$, if needed) is the $e$ you are looking for. The $k$ is totally irrelevant for encryption/decryption, but it's actually the $y$ in the above equation (rewrite your equation and see).

Henno Brandsma
  • 3,842
  • 16
  • 20
  • HI, so a question I am working on asks to find d given the public key N and e. But I didn't think it was possible unless you knew what p1 and p2 are so you can find phi(N). I am given e and N but not p1 or p2 so how do I find what d is? – User Nov 13 '18 at 22:04
  • I am trying a couple things to figure out how to find D given e and N so if I am doing something wrong just let me know. – User Nov 13 '18 at 22:05
  • 1
    @User You cannot, unless it's a puzzle with a special trick. Like taking $d$ too small, or $N$ being easily factorisable etc. – Henno Brandsma Nov 13 '18 at 22:05
  • I think your right since N is a small number. – User Nov 13 '18 at 22:17
  • Ok so I factored N and got phi(N) so to find d I guess I do d = e^-1 mod phi(N) – User Nov 13 '18 at 22:28
  • Given that I know e and phi(N) I am not sure how to calculate the inverse? – User Nov 13 '18 at 22:29
  • @User Apply the extended Euclidean algorithm, as I said. The wiki link I gave has a description. – Henno Brandsma Nov 13 '18 at 22:30
  • 1
    @User https://wolframalpha.com also does modular inverse for you. Or the Crypto modulo in Python. etc. – Henno Brandsma Nov 13 '18 at 22:32