# Public key cryptography - public key encrypts and cannot decrypt?

I understand the basics behind public key cryptography, in that each party has two keys - the public one encrypts, and the private one decrypts. What I cannot figure out is, How does the public key encrypt and not decrypt, but yet the private key can decrypt?
I do understand the possibilities of this, but, does anyone know what cipher can do this, and how does this practically operate?

-

## 2 Answers

How it works depends on the cipher, but the basic idea is that of a trapdoor function.

A trapdoor function is a function that is easy to compute in one direction, yet believed to be difficult to compute in the opposite direction (finding its inverse) without special information, called the "trapdoor".

Many number theoretic problems have been used in the past successfully to build such functions, and the wikipedia article is fairly good.

Let's take one as an example, lets say the problem of factoring a number into it's prime factors. Every number can be uniquely broken up into a product of primes. It turns out though, that breaking a number up into its prime factors is difficult if the number is large enough and the factors are large enough, but give me a few large prime numbers and I can easily compute the composite that those numbers make up.

So, how can this be leveraged with cryptography? I choose say two large prime numbers called $p,q$ and set $n=p\cdot q$. I then set $e=65567$ and give you $e,n$. I then use my extra information ($p,q$) to compute $d$ such that $ed\equiv 1\pmod{\phi(n)}$. This can only be efficiently computed if you know $p$ and $q$.

You have $e,n$, so to send me a message $m$ you compute $c=m^e\bmod{n}$ and send $c$ to me. For me to get $m$ back, I must know $d$, I can only know $d$ if I know $p,q$ and you knowing only $n$ and $e$ cannot compute $d$.

To get $m$ back I compute $c^d\equiv (m^e)^d \equiv m^{ed} \equiv m^1 \equiv m\pmod{n}$, so I have successfully used my extra information to recover $m$, something you cannot do without the extra information.

The public key can encrypt (it is the forward direction of the "one-way function"), but cannot decrypt because it does not know the trapdoor information to go in the reverse direction.

The cipher described here is RSA. There are others, but RSA is pretty simplistic.

-

quote: "such that ed ≡ 1 mod n. This can only be efficiently computed if you know p and q." Is that: ed ≡ 1 (mod n)? – AUTO Dec 8 '12 at 21:21
– David Cary Dec 9 '12 at 1:27

If you are talking about RSA public key encryption the albebraic structure of the construction and some number theory will clear your puzzled situation. There is no meaning to write down how RSA works.Have a look here here

"$d$ is the multiplicative inverse of $e$: $ed\equiv1 \pmod{n}$. That's why $(m^e)^d \pmod{n}=m$

-

1
I think you meant $(m^e)^d \pmod{n} = m$. – Thomas Dec 9 '12 at 5:11
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 28, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.3, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9461008906364441, "perplexity_flag": "head"}