# Prime numbers

**URL:** <https://boards.straightdope.com/t/prime-numbers/842498>\
**Category:** Factual Questions\
**Created:** [October 26, 2019, 3:25pm UTC](https://boards.straightdope.com/t/prime-numbers/842498 "2019-10-26T15:25:27Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Bryan\_Ekers](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bryan_ekers/32/183_2.png) [@Bryan\_Ekers](https://boards.straightdope.com/u/Bryan_Ekers)\
**Post date:** [October 26, 2019, 11:25pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/21 "2019-10-26T23:25:46Z")

</div>

It was in hexadecimal, I just didn’t type any letters. Satisfied?

---

<div class="post-metadata">

**Author:** ![Bryan\_Ekers](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/bryan_ekers/32/183_2.png) [@Bryan\_Ekers](https://boards.straightdope.com/u/Bryan_Ekers)\
**Post date:** [October 26, 2019, 11:55pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/22 "2019-10-26T23:55:39Z")

</div>

I decided to just look it up and learned RSA Labs [was running contests](https://en.wikipedia.org/wiki/RSA_numbers) where they would publish various-sized _N_ values and award prizes for anybody who could find the appropriate _p_ and _q_. The smallest _N_ not yet factored (admittedly, I expect interest fell off significantly when RSA stopped giving cash prizes) is the 232-digit 1009881397871923546909564894309468582818233821955573955141120516205831021338528545374366109757154363664913380084917065169921701524733294389270280234380960909804976440540711201965410747553824948672771374075011577182305398340606162079.

So… y’know… go nuts.

---

<div class="post-metadata">

**Author:** ![pulykamell](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pulykamell/32/3166_2.png) [@pulykamell](https://boards.straightdope.com/u/pulykamell)\
**Post date:** [October 27, 2019, 12:02am UTC](https://boards.straightdope.com/t/prime-numbers/842498/23 "2019-10-27T00:02:25Z")

</div>

> [@Bryan\_Ekers](#):
>
> It was in hexadecimal, I just didn’t type any letters. Satisfied?

Well, FWIW, the final factorization was: 3343 × 80814 362767 × 49088 464232 315669 000167 × 121139 790939 541766 433273 004057 × 5772 669804 501159 736144 919275 294300 097290 818445 203478 308604 682152 212381 606211 094953 930153

and took 18 minutes. Damn. I’m impressed. (Then again, there was one pretty low prime factor, and another one relatively low). [Here’s the site I used](https://www.alpertron.com.ar/ECM.HTM) for those interested.

---

<div class="post-metadata">

**Author:** ![Yask](https://avatars.discourse-cdn.com/v4/letter/y/eb9ed0/32.png) [@Yask](https://boards.straightdope.com/u/Yask)\
**Post date:** [October 28, 2019, 4:50pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/24 "2019-10-28T16:50:10Z")

</div>

> [@Bryan\_Ekers](#):
>
> One of the more common applications (though most people using it don’t understand or need to care about the mechanics) is RSA cryptography, allowing a person to send secret messages. The gist (highly simplified) is that:
> 
> Secretly choose a prime number _p_, which by definition can only be divided by 1 and _p_ itself.  
> Secretly choose a different prime number _q_, which by definition can only be divided by 1 and _q_ itself.  
> Multiply _p_ and _q_ to get _N_. _N_, therefore, will only be divisible by 1, _p_, _q_ and _N_ itself.
> 
> What allows RSA cryptography to work is that once you’ve chosen _p_ and _q_, generating _N_ is easy. If all you have is _N_, trying to work backward to find _p_ and _q_ is difficult.
> 
> Picture 15. Very quickly, anyone can see that its _p_ and _q_ are 5 and 3. But what if _N_ is 927401749817398759182759192911 ? How long would it take even a very fast computer to find _p_ and _q_? Years? Centuries? The age of the universe?
> 
> Anyone can generate their own _N_ and publish it freely. This becomes their “public key”. If I wish to send a secret message to someone, I will use their public key to encrypt it. Then it doesn’t matter who might see the encoded message, because the only way to decrypt it is by using _p_ and _q_, which the recipient knows and has _not_ published, as they form his “private key”.

I’m sorry to be a bother, but I’m not quite following the end of your explanation. To keep it simple, let’s say that it’s not easy for anyone to see that 5 (_p_) and 3 (_q_) are the prime factors of 15 (_N_). I want to send you a secret message. You give me 15 as your public key. Now what?

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [October 28, 2019, 5:29pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/25 "2019-10-28T17:29:18Z")

</div>

> [@Yask](#):
>
> I’m sorry to be a bother, but I’m not quite following the end of your explanation. To keep it simple, let’s say that it’s not easy for anyone to see that 5 (_p_) and 3 (_q_) are the prime factors of 15 (_N_). I want to send you a secret message. You give me 15 as your public key. Now what?

N is generated as part of the key, but you also need to pick an exponent for your public key, like 3. Now to encrypt a message like “7”, compute 7^3 modulo 15, which gives “13”. To decrypt you compute 13 to the power of the secret key, also 3 in this example. Needless to say, this is more practical using bigger numbers. See the articles on [RSA cryptosystems](https://en.wikipedia.org/wiki/RSA_(cryptosystem))

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [October 28, 2019, 5:51pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/26 "2019-10-28T17:51:54Z")

</div>

I forgot to explain the most important thing: the reason why you need to factor N is to be able to compute the decryption key given the public, encryption key.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [October 28, 2019, 6:58pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/27 "2019-10-28T18:58:00Z")

</div>

Although it focuses on one specific problem — the most famous of all the Million-Dollar math problems, RH — [Derbyshire’s _Prime Obsession_](https://www.amazon.com/Prime-Obsession-Bernhard-Greatest-Mathematics/dp/0452285259) is an excellent read, accessible to the layman.

> [@](#):
>
> In the early 1900s, British mathematician Godfrey Harold Hardy sometimes took out a quirky form of life insurance when embarking on ocean voyages. In particular, he would mail a postcard to a colleague on which he would claim to have found the solution of the Riemann Hypothesis. Hardy was never on good terms with God and felt that God would not let him die in a sinking ship while Hardy was in such a revered state, with the world always wondering if he had really solved the famous problem.

---

<div class="post-metadata">

**Author:** ![zimaane](https://avatars.discourse-cdn.com/v4/letter/z/a3d4f5/32.png) [@zimaane](https://boards.straightdope.com/u/zimaane)\
**Post date:** [October 28, 2019, 7:35pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/28 "2019-10-28T19:35:49Z")

</div>

It’s hard to overstate how important this. Every time you send a credit card number over the internet this procedure (or something similar) is used to encode your message. Modern e-commerce would not be possible without it.

---

<div class="post-metadata">

**Author:** ![ftg](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ftg/32/2801_2.png) [@ftg](https://boards.straightdope.com/u/ftg)\
**Post date:** [October 28, 2019, 9:12pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/29 "2019-10-28T21:12:30Z")

</div>

Note that RSA itself is quasi-deprecated by the Crypto community. It’s just not secure enough at the bit sizes needed to do rapid transactions. Look at the table [here](https://en.wikipedia.org/wiki/Transport_Layer_Security#Key_exchange_or_key_agreement) and note how the latest TSL standard is dropping some forms of it.

[AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) and [SHA-2](https://en.wikipedia.org/wiki/SHA-2) are currently the most common system used to encrypt Internet traffic. But like RSA, SHA-2 is being deprecated. SHA-2 reverse hashing is also used as the “work” in Bitcoin mining. So that’s a _lot_ of cycles being used on that right now.

If you search the SHA-2 article for “prime” you will see several places in the code where they are used. But these are small potatoes compared to RSA.

(Note: I am far from an expert on this. But I’m a bit more knowledgeable than the average CS nerd. I was “near” to lot of early public key stuff. E.g., a week after RSA had been developed I was in the back seat of a car with R and A. But compared to Real Experts I’m practically a noob.)

---

<div class="post-metadata">

**Author:** ![Chronos](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/chronos/32/134_2.png) [@Chronos](https://boards.straightdope.com/u/Chronos)\
**Post date:** [October 28, 2019, 9:19pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/30 "2019-10-28T21:19:56Z")

</div>

> [@](#):
>
> Quoth **septimus** :
> 
> For a loosely related reason, it is often good practice to arrange that the number of teeth on two interacting gears be relatively prime to each other.

Note that “relatively prime” is not the same thing as “prime”. Two numbers are relatively prime if they have no factors in common (other than 1). For instance, 9 and 10 are relatively prime to each other. But a prime number is relatively prime to _everything_.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [October 28, 2019, 10:06pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/31 "2019-10-28T22:06:21Z")

</div>

> [@septimus](#):
>
> Yes. BTW, sometimes “quadratic reprobing” is useful (m, m+1, m+4, m+9, …) although it visits only half the table.

It’s really much easier to use a power-of-2 table size and a probe function of n(n-1)/2. Visits the whole table and no funny business with primes.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [October 28, 2019, 10:12pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/32 "2019-10-28T22:12:25Z")

</div>

> [@ftg](#):
>
> Note that RSA itself is quasi-deprecated by the Crypto community. It’s just not secure enough at the bit sizes needed to do rapid transactions.

Maybe so, though Diffie–Hellman key exchange is still in widespread use and also depends on the properties of large prime numbers.

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [October 29, 2019, 9:13am UTC](https://boards.straightdope.com/t/prime-numbers/842498/33 "2019-10-29T09:13:07Z")

</div>

> [@Dr.Strangelove](#):
>
> It’s really much easier to use a power-of-2 table size and a probe function of n(n-1)/2. Visits the whole table and no funny business with primes.

Nitpicks:

- If 134 million entries isn’t quite enough, you’ll need 268 million with that scheme. This is too profligate if memory is scarce.
- Taking residue with a prime divisor provides a “hashing” (randomization) utility that power-of-two divisors lack.
- When quadratic reprobing is used, a tiny number of additional lines of code suffice to probe the other half of the table if necessary.
- Anyway, reprobing is altogether unnecessary with some of the best hash table schemes.

---

<div class="post-metadata">

**Author:** ![Dr.Strangelove](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/dr.strangelove/32/6613_2.png) [@Dr.Strangelove](https://boards.straightdope.com/u/Dr.Strangelove)\
**Post date:** [October 29, 2019, 9:49am UTC](https://boards.straightdope.com/t/prime-numbers/842498/34 "2019-10-29T09:49:03Z")

</div>

> [@septimus](#):
>
> Nitpicks:

Depends on the application, sure. Though I’d be curious if you know anything about the typical distribution of probes between the two cases. I’m not super convinced that the mod p effect is really any more effective at spreading out the probes.

I sorta reminded myself that I’d always been curious about a proof that triangular number probing (still quadratic, of course) hits every element in a 2^b size table. I found one, but didn’t read it. Nothing has come to mind yet aside from the obvious fact that on the Nth probe, the next index will repeat and thus collide (since n(n-1)/2 + n = (n+1)n/2).

---

<div class="post-metadata">

**Author:** ![Hari\_Seldon](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/hari_seldon/32/5173_2.png) [@Hari\_Seldon](https://boards.straightdope.com/u/Hari_Seldon)\
**Post date:** [October 29, 2019, 1:26pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/35 "2019-10-29T13:26:04Z")

</div>

> [@ftg](#):
>
> Note that RSA itself is quasi-deprecated by the Crypto community. It’s just not secure enough at the bit sizes needed to do rapid transactions. Look at the table [here](https://en.wikipedia.org/wiki/Transport_Layer_Security#Key_exchange_or_key_agreement) and note how the latest TSL standard is dropping some forms of it.
> 
> [AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) and [SHA-2](https://en.wikipedia.org/wiki/SHA-2) are currently the most common system used to encrypt Internet traffic. But like RSA, SHA-2 is being deprecated. SHA-2 reverse hashing is also used as the “work” in Bitcoin mining. So that’s a _lot_ of cycles being used on that right now.
> 
> If you search the SHA-2 article for “prime” you will see several places in the code where they are used. But these are small potatoes compared to RSA.
> 
> (Note: I am far from an expert on this. But I’m a bit more knowledgeable than the average CS nerd. I was “near” to lot of early public key stuff. E.g., a week after RSA had been developed I was in the back seat of a car with R and A. But compared to Real Experts I’m practically a noob.)

I’m even less than an expert, but I know that AES is a symmetric key encryption which obviates having a public key. I couldn’t quite figure out whether SHA is. But my impression is that RSA, though rather slow, is still used in conjunction with AES to send out the required key for a symmetric system. So if you use a product of two 500 digit primes (or even pseudoprimes) it will be very slow to encrypt and decrypt the needed key, but it need be done only once for each message.

Aren’t there public key methods based on discrete logarithms or on the arithmetic of elliptic curves? Will they succumb to quantum computers?

---

<div class="post-metadata">

**Author:** ![septimus](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/septimus/32/410_2.png) [@septimus](https://boards.straightdope.com/u/septimus)\
**Post date:** [October 29, 2019, 2:30pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/36 "2019-10-29T14:30:53Z")

</div>

> [@Dr.Strangelove](#):
>
> I sorta reminded myself that I’d always been curious about a proof that triangular number probing (still quadratic, of course) hits every element in a 2^b size table. I found one, but didn’t read it. Nothing has come to mind yet aside from the obvious fact that on the Nth probe, the next index will repeat and thus collide (since n(n-1)/2 + n = (n+1)n/2).

I’d never heard of this nifty fact! A little Googling suggests that Donald Knuth _might_ be the discoverer, but I stopped Googling when I also decided to add “Try to find a proof” to my To-Do list.

But I still like prime-sized tables. And when feasible, Cuckoo Hash Tables seem like a good way to go: trivial “reprobing,” efficient in space and time, quite flexible and very elegant!

---

<div class="post-metadata">

**Author:** ![Buck\_Godot](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/buck_godot/32/6573_2.png) [@Buck\_Godot](https://boards.straightdope.com/u/Buck_Godot)\
**Post date:** [October 29, 2019, 5:20pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/37 "2019-10-29T17:20:23Z")

</div>

> [@Hari\_Seldon](#):
>
> That’s only 154 digits. I think such numbers can now be factored, although not easily. But the product of two 500 digit primes will be essentially unfactorable, at least without a quantum computer.
> 
> One interesting fact is that there are algorithms that can quickly test to see if a 500 digit prime with 99.9999999…% probability. There are also much slower ones that give 100% but I doubt they are worth the effort. This is what makes RSA encryption so successful.

In order to avoid a [severe hijack](https://boards.straightdope.com/sdmb/showthread.php?t=32760), please find a different notation to indicate a 99.99 with an arbitrarily large but finite number of 9’s if you want to distinguish it from 100%. 😉

> [@am77494](#):
>
> With the cryptography applications mentioned, it is also to be said that math guys love prime numbers for the same reason climbers like mountains. They are challenging to get to.

Not me. I’m a math guy and I can’t stand prime numbers because they are such a pain to work with. On the other hand I also think that people who climb mount Everest are crazy.

---

<div class="post-metadata">

**Author:** ![Pleonast](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/pleonast/32/1183_2.png) [@Pleonast](https://boards.straightdope.com/u/Pleonast)\
**Post date:** [October 29, 2019, 5:34pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/38 "2019-10-29T17:34:00Z")

</div>

> [@Chronos](#):
>
> Note that “relatively prime” is not the same thing as “prime”. Two numbers are relatively prime if they have no factors in common (other than 1). For instance, 9 and 10 are relatively prime to each other. But a prime number is relatively prime to _everything_.

A prime number is not relatively prime to itself. And that actually matters in gearing.

---

<div class="post-metadata">

**Author:** ![iamthewalrus\_3](https://avatars.discourse-cdn.com/v4/letter/i/258eb7/32.png) [@iamthewalrus\_3](https://boards.straightdope.com/u/iamthewalrus_3)\
**Post date:** [October 29, 2019, 6:40pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/39 "2019-10-29T18:40:39Z")

</div>

> [@TriPolar](#):
>
> Really? You think that was needed to determine whether a set of 19 or less objects could be evenly divided?

No, the bone wasn’t required to know that. The bone was an artifact that noted the thing they had figured out.

Like, you don’t need a multiplication table to know how to multiply, but a multiplication table is an artifact of having figured out some useful amount of math and written it down.

I can easily believe that numbers that won’t evenly divide would be useful to know in early human society, given how greedy and attuned to inequality we are.

---

<div class="post-metadata">

**Author:** ![DPRK](https://avatars.discourse-cdn.com/v4/letter/d/4491bb/32.png) [@DPRK](https://boards.straightdope.com/u/DPRK)\
**Post date:** [October 29, 2019, 6:55pm UTC](https://boards.straightdope.com/t/prime-numbers/842498/40 "2019-10-29T18:55:17Z")

</div>

> [@Hari\_Seldon](#):
>
> I’m even less than an expert, but I know that AES is a symmetric key encryption which obviates having a public key. I couldn’t quite figure out whether SHA is. But my impression is that RSA, though rather slow, is still used in conjunction with AES to send out the required key for a symmetric system. So if you use a product of two 500 digit primes (or even pseudoprimes) it will be very slow to encrypt and decrypt the needed key, but it need be done only once for each message.

That is indeed how it is used in practice. There was some vulnerability involving the specific TLS\_RSA implementation, but like you I am not an expert on TLS and don’t know how widely applicable it is. It definitely serves to illustrate that badly-implemented RSA is vulnerable to side-channel attacks as well as direct cryptographic attacks.

SHA is a (family of) cryptographic hashing algorithms.

> [@](#):
>
> Aren’t there public key methods based on discrete logarithms or on the arithmetic of elliptic curves? Will they succumb to quantum computers?

I’m not an expert on this field either, but certainly there are quantum algorithms and [this (old!) paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2017/09/1706.06752.pdf) suggests that elliptic-curve arithmetic is more vulnerable than straight RSA.

[Previous page](https://boards.straightdope.com/t/prime-numbers/842498.md?page=1)

[Next page](https://boards.straightdope.com/t/prime-numbers/842498.md?page=3)
