r/ComputerSecurity • • Mar 28 '23

Generating large prime numbers

(EDIT: Solved! Found the answer, it's in the comments below, I was missing an algorithm.)

For RSA encryption two large primes are needed. On online sites, they can be generated in milliseconds up to 2048 bit sizes.

My problem is that finding these large primes is quite hard. According to this stack exchange question, the best way is using a combination of Fermat and Miller-Rabin tests, each done multiple times.

Fermat: an-1 mod n = 1

The problem is, using Fermat's test, the faster of the two, and using the simplest and smallest number a = 2, I can't come remotely close to testing a prime in the needed range, atleast 10^150.

My computer can't even calculate n=10^20, as you need to take a10^20 - 1, and I don't have enough memory for that.

What can i do?? Even the simplest version of the simplest test would take billions of times the memory I have, not even counting the run time.

It's obviously possible, but I can't find anything anywhere on how!

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/Soxcks13 Mar 28 '23

Sorry my short answer is “I don’t know”.

I’d be interested in an answer. But I would think you’d need to store numbers as byte streams, and perform mathematical operations based on chunks of bytes. I don’t know how to do this in practice though. Best of luck!

2

u/LordTachankaMain Mar 28 '23

think i found the answer. there is an algorithm to split up that large number, so it doesnt have to be calculated. https://www.geeksforgeeks.org/find-abm-where-b-is-very-large/