Factoring RSA Keys with Python

One of the projects I’m starting to work on lately is factoring large RSA keys with Python. This project has always interested me, I like the challenge of something that is impossible because I don’t believe in them until I try and it gves me something to send my ADHD brain into a problem.

Now I’m under no illusion this is an easy task for factoring RSA keys. I’ve read plenty of posts on the web and reddit, and so far nobody has factored RSA617 or RSA2048 keys. Simply because of the computational power required.

 

Disclaimer: This page contains affiliate links. Predominantly as an an eBay Partner Affiliate, Google Adsense and Amazon Affililate and as a member of other affiliate networks. If you choose to make a purchase after clicking a link, I earn from qualifying purchases and may receive a commission at no additional cost to you.

 

I believe this can be done, and I want to prove it. For me this is a learning experience though. I don’t know Python, so I’m using it as opportunity to learn. I’m busy writing myself a Python code (utilising ChatGPT helps immensely with learning) for outputting different features that I want.

It’s then a case of building my Python script and running in on the Raspberry PI, or my CUDA card when I receive it.

All factoring laws follows basic laws in mathematics. So I’m aiming to remove unncessary calculations (somehow) I’m not sure how yet in Python, so could be adding to this post as I go.

The way I see it with this calculation, even though the number of possiblities stays the same. If I can remove the other 8 number chains in the pool to verify if they’re not needed. I’ve removed 80% of the numbers that I need to work with. If for example for RSA2048 the starting factors begin with 5, and 9. Then I can basically ignore any formulas using the other 8 numbers (1,2,3,4,6,7,8,0). The more I can remove the less that the Python has to calculate.

Removing the number of permutations by this method along a few others I’m thinking about will weaken the key purely on the reasons of there’s less combinations that can exist

I did initially try using the script to generate a file as if I would do a dictionary attack using the number outputs which would be way faster. However I underestimated how much space those digits take up. I computed 7 digits out of the 600 digits and the file filled up my 30GB SD card.

In order to store everything I’d probably need a hard disk several TB in size. This would at least benefit me if created however long it would be as I’d have the full list of numbers then. I do have a method in mind to speed it up and find only the numbers I need but again that relies on me with Python. I’m developing the knowledge the more I run the scripts and learn what to use from Googling so hoping my knowledge gets better to improve the efficiency on the scripts.

I tried running as a test on my Python, whilst it did work on the easier numbers, it was running endlessly on the larger ones in it’s current state. The CPU core also nearly hit 80’c , so I added a copper heatsink with some thermal glue to reduce the operating temperature. As carrying out RSA factoring hammers the CPU on almost any computer.

My goal for calculating RSA simply involves removing every possibility until I only have to work with correct numbers. I would like to brute force it, and go from there. I’ve been making lots of notes, so also worked out (I think) on how to verify numbers are in incorrect order in the sequences.

I’d like to write a windows program as it would be faster than Python I think based on how I want to calculate the results but one step at a time.

At the moment I’m starting on the smaller known numbers like RSA-100 just as initial testing, so that I can learn where I need to go from, and how to improve it. Then when I’m ready for the final run, I’m going to leave the computer switched on and have it run. Once I factor RSA-100 with Python successfully, i can go from there.

Once an initial script is done, it’s simply a case of the computer brute forcing every possbile key variations (of which there are lots). If you’ve ever seen War Games (good movie), when W.O.P.R is searching for the thermonuclear launch codes, it’s basically brute forcing the key by trying every permutation one by one. The same type of principle applies for permutation cracking with RSA, except there are two keys which are extremely long in length. Which is why no one bothers with it.

The basic laws of math still apply however when it comes to RSA. This is one of the weakpoints in it that can be exploited. Security can still be increased however by the combination of salts, however at this moment in time I’m purely interested in the calculation of basic security for the purposes of factoring RSA with brute force and simplifying it

At the time of the update on this post (04/06/26). I estimate I’ve removed approximately 98% of the numbers required in the RSA calculation,  I have an idea of the starting range I need to use. Once I get to the point where I’ll be starting, I’ll get my CUDA card out and see if I can use ChatGPT to write me some CUDA code, and then also a python script to accelerate it all on the function I want to use

In terms of factoring RSA, basic math laws CANNOT be broken. Your available digits are 0-9, and you’re always adding and multiplying numbers. You also cannot make a number larger than a value of it’s starting digit without adding another digit, nor can it take the next power.

FOR EXAMPLE 9×9 = 81, you CANNOT make 82 using this no matter how many combinations you have without adding more digits. Number combinations on RSA are finite because of the available characters (RSA-617 is something like 308 and 309 digits). So the number you output can only have a maximum of 309 digits to generate the number

 

I know this sounds weird because I’m typing it, but it’s all in my head how it’s being calculated and I’ve been writing a lot down onhow it’s to work as math.  I spend a lot of time looking at earlier numbers to identify patterns I can exploit to reduce my number queries.

Verifying

Leave a Comment

Your email address will not be published. Required fields are marked *

Recipe Rating




Exit mobile version