GENERATE PRIME NUMBERS

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

GENERATE PRIME NUMBERS

Post by devendra-m »

I am trying to implement RSA in PHP. But I am not being able to generate 128bit prime numbers. Do you how to generate 128 bit prime numbers.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Without a solid mathematical foundation, I would strongly advise against attempting to implement RSA in PHP due to the high probability of implementation errors. Try: http://pear.php.net/package/Crypt_RSA
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Writing your subject all in caps is not going to get more people to try and answer your question.


I assume you are trying to generate a 256bit key. To generate a 128 bit prime you need to choose a random 128 bit number, then start looking at every odd number greater than that number and run primality tests on it to see if it is prime. To have it be secure your random number has to truly be random. For instance if you run this client side in javascript to send a password over, I am guessing it is not going to be secure.

Here is a discussion of primality tests

http://en.wikipedia.org/wiki/Primality_test
Post Reply