How can I simulate and measure brute force hacking using RSA?

I want to implement brute force hacking using RSA. How can I simulate and measure time duration? What software (or software-based simulator) would be needed?

-
First, you shoudl specify, what you actually want to brute-force. Is it factoring $n$, or finding $d$, or finding $m$ to a certain ciphertext $c$? Anyway, brute force in general is a bad idea here, since the "try out everything" approach has a MUCH higher complexity than factoring with the GNFS (very rough approximation: $2^{n}$ vs $2^{n/3}$) –  tylo Feb 10 at 13:38
Maybe you meant RSA hacking using brute force? –  catpnosis Feb 11 at 3:23

Firstly, I assume we are talking about classical computers

Implementing a brute force attack on a RSA may not be the most sensible thing, unless of course the security parameter of your target system is small.. (160 bit numbers! )

Even then you may not want to implement a brute force here.. try using Fermat's Factoring or Pollards $\rho$ method.

If you just want to measure time try to do a more theoretical research, i.e. use the time take per multiplication op. and the no. of operations your computer can perform in a sec to determine exactly how long will it take you to brute force a $n-$bit security.

To sum it up, YOU CANNOT BRUTE FORCE THE (properly implemented) MODERN DAY RSA (~4096 bit numbers) even if you use all computers in your state.

-
Did you mean 160 digits (about 530 bits) rather than 160 bit? That's more like the limit of brute-forcing RSA for an individual. –  fgrieu Feb 9 at 17:00
160 bits sound about right if by "brute force" one means literally iterating through all odd numbers from $\sqrt(N)$ and checking if the value divides $N$. –  Henrick Hellström Feb 10 at 1:33
@fgrieu 530 bit is in the ballpark of brute force, however, it will take some time (months) to do that with a modern day PC (I assume the asker does not have access to supercomputers or clusters). –  Subhayan Feb 11 at 3:18

I don't understand what you mean simulate, but if you need a toy example in python the code is at the end of the message. If you need to show the performance of more advanced algorithms use factor(x) in pari/gp. See here for details.

import gmpy, time, random, math

def genprime(bits):
p=1
while(gmpy.is_prime(p)==0):
p = random.randrange(math.pow(2,bits-1),math.pow(2,bits))
return p

BITS=20
found=False
p=genprime(BITS)
q=genprime(BITS)
n=p*q
cnt=2
s_time=time.time()
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7391436696052551, "perplexity": 1547.5569355936457}, "config": {"markdown_headings": false, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-15/segments/1397609532128.44/warc/CC-MAIN-20140416005212-00013-ip-10-147-4-33.ec2.internal.warc.gz"}