Prime Numbers

Boy, oh boy, have I been having fun lately! I’ll tell you the short version of the story:

I needed an RSA algorithm (to perform asymmetrical encryption) for a PHP script I’m writing. I couldn’t use the OpenSSL module because I wanted the script to be portable. So I searched and searched for a purely PHP implementation of the RSA algorithm, but couldn’t find one anywhere. So I had to learn how it worked so I could implement it myself.

I found the most amazing math article I had ever read and after hours and hours, I had a key generator that was capable of generating keys upwards of 2024 bits!

But during those hours and hours, I fell in love with prime numbers! So for fun, I posted (well, I tried to post it. I ended up uploading a text file that is now available for download) a list of 83,641 prime numbers, generated by yours truly (well… by a script that yours truly wrote at least).

So that’s that. Prime numbers. If you’re having the same issues with finding RSA in PHP, here’s a link to my classes. I didn’t really make them to be portable (EDIT: I rewrote the code. It is now portable and you are free to use it how you wish), so in the RSA_Handler class, there are a few things that I did my own way (mostly in the generate_keys and encrypt functions), but you should still be able to see how it works. If you want the most basic usage, use an RSA_keymaker object and the make_keys function. The function will return an array of keys (in number form) where $keys[0] is the public key, $keys[1] is the private key and $keys[2] is the modulo. The keys generated with the default function are around 1024 bits (a 310 digit modulo).

One Response to “Prime Numbers”

  1. Hannah Says:

    My suspicions were correct. You’re nuts. Meaning you seem to be an amazing expert in your field and I wouldn’t try and touch this stuff with a 10 foot pole. 🙂

Leave a Reply