Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

Is there a effective quick way to generate a large prime of a given length?

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

I know where you are going with this and it is not necessary.

To answer your question, there is no extremely quick way.

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

Where am I going?

```
while True:
randomnumber = random.randrange(2**(length-1),(2**(length))-1)
if primep(randomnumber):
print randomnumber
break
```

Thats all I got from stackoverflow

*Last edited by Agnishom (2013-09-21 21:16:47)*

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

You think you need a large prime to learn Diffie- Hellman. I can denmonstrate the procedure using a small one.

Thats all I got from stackoverflow

Hohohohohohohahahaha, they are always good for a laugh. To think that such brilliant people can still have a wonderful sense of humor gives me much hope for the human race.

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

bobbym wrote:

You think you need a large prime to learn Diffie- Hellman. I can denmonstrate the procedure using a small one.

I can too. But that is not secure enough.

Sorry, I did not get the humor

'And fun? If maths is fun, then getting a tooth extraction is fun. A viral infection is fun. Rabies shots are fun.'

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

I agree. But I thought you wanted to see how it worked?

**In mathematics, you don't understand things. You just get used to them.Of course that result can be rigorously obtained, but who cares?Combinatorics is Algebra and Algebra is Combinatorics.**

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

I think the only problem is - after Alice and Bob have the shared secret, how do they exchange messages using it?

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

I have been waiting to answer that one since yesterday. But it seems I have missed Agnishom today.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

anonimnystefy wrote:

I think the only problem is - after Alice and Bob have the shared secret, how do they exchange messages using it?

They use a symmetric cypher, like RC4 with the key.

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

Let us take the generally accepted *p* from http://tools.ietf.org/html/rfc2409#section-6.2

`179769313486231590770839156793787453197860296048756011706444423684197180216158519368947833795864925541502180565485980503646440548199239100050792877003355816639229553136239076508735759914822574862575007425302077447712589550957937778424442426617334727629299387668709205606050270810842907692932019128194467627007`

The generator g is

`2`

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Hi Agnishom

My number:

`170889576082067697731054176601909874828559452754928289693960008087616417613737398548717155229171096112124599345710842437121675819339812482513978573388985033018038377053945453188374711735023121936105534290646082341664680937820085667262891263915428892361981765346083422852575547729295502827704976423861860303103`

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

Hi anonymnesty,

g[sup]b[/sup] (mod p)

`173419298906489863864646388281941306843742681293608592957943679413527102401811311961611828206757391788738800024670641247258673805804085888390828078173388181181530749311360724611386280929348614725682444473741887149211776384725911058474047582365359321545094524307293842804350322782081718297375589621859722244791`

*Last edited by Agnishom (2013-09-22 16:34:05)*

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Hm, just call me Stefy. It's easier for everybody that way.

Here lies the reader who will never open this book. He is forever dead.

Taking a new step, uttering a new word, is what people fear most. ― Fyodor Dostoyevsky, Crime and Punishment

Offline

Hi Stefy,

Sorry for the typo. Is what you posted in #11 g[sup]a[/sup] (mod p) ?

How should I use the secret key to message you now? What about RC4?

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**auyeungyat****Member**- Registered: 2013-09-23
- Posts: 15

I have tested on my computer(Mac on Terminal).That doesn't generate any numbers!

Offline

auyeungyat wrote:

I have tested on my computer(Mac on Terminal).That doesn't generate any numbers!

I am sorry, primep is defined externally. Do you want the full working code?

*Last edited by Agnishom (2013-09-23 03:02:37)*

'God exists because Mathematics is consistent, and the devil exists because we cannot prove it'

'Humanity is still kept intact. It remains within.' -Alokananda

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Agnishom wrote:

Hi Stefy,

Sorry for the typo. Is what you posted in #11 g[sup]a[/sup] (mod p) ?

How should I use the secret key to message you now? What about RC4?

It is.

Is there something more simple we could try first?

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

I have a nice tut on this if you need to see how it is done.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Hi bobbym

You can post them, if you want.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

It uses baby sized numbers but maybe that is best for an example.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Sure. Any example would suffice, seeing how I am not sure at all how to use the shared secret.

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

Neither am I. How about we try to follow their example?

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Their?

Here lies the reader who will never open this book. He is forever dead.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 86,264

The video I have. They use an example. They go through the technique step by step. Should be easy to do with a real problem later on.

Of course that result can be rigorously obtained, but who cares?

Combinatorics is Algebra and Algebra is Combinatorics.

Offline

**anonimnystefy****Real Member**- From: The Foundation
- Registered: 2011-05-23
- Posts: 15,522

Could you post the link to the video?

Here lies the reader who will never open this book. He is forever dead.

Offline