0

For security purpose testing, I am trying to write JavaScript code that calculates the possibilities of 5 length password.

The strikes on keyboard are

a b c d e f g h i j k l m n o p q r s t u v w x y z

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

0 1 2 3 4 5 6 7 8 9 

! @ # $ % ^ & * ( ) _ + } { " : ? > <

How do I writes loops in JavaScript to print all the possibilities without making the computer hangout/freeze assuming the output number is going to be really huge.

Also how do I calculate the time needed to finish the process?

Ahmed Shahin
  • 74
  • 1
  • 8
  • @DM Its not , I need to print all the possible letters , numbers and symbols for 5 length password, – Ahmed Shahin Dec 14 '21 at 20:41
  • 1
    Just pass an array containing all the possible letters, numbers and symbols as the parameter then. – Spectric Dec 14 '21 at 20:42
  • I got it , how do i calculate time ? – Ahmed Shahin Dec 14 '21 at 20:43
  • 1
    You can't predict how long the program will take to execute. – Spectric Dec 14 '21 at 20:44
  • @Spectric why not , if i can tell how many output result in 1 sec , I can figure the time estimation at least , no ? for example if the total output is 10 , and each 1 second you finished 1 probability . then the time needed to finish this is 10 seconds – Ahmed Shahin Dec 14 '21 at 20:49
  • Sounds like an [XY Problem](https://xyproblem.info)
 - It is unclear _why_ you need to do this. What specific problem are you trying to solve? If simply trying to enforce a set of rules, validate the input against the rules. – Randy Casburn Dec 14 '21 at 20:49
  • @RandyCasburn I already wrote , I need it for security purpose – Ahmed Shahin Dec 14 '21 at 20:51
  • What _specific_ security purpose? Having all possible 5 letter combinations of letters has nothing to do with security. The way you might use those combinations does - that would be the specific part. – Randy Casburn Dec 14 '21 at 20:52
  • @RandyCasburn it's hard to go in details , but this is related to a research am writing for brutal force attack on the internet and how to protect against it . Thanks for your comment , I think I already found the answer on forums – Ahmed Shahin Dec 14 '21 at 20:56
  • The question itself is not practical, printing 81!/76! permutations is not realistic. – Teemu Dec 14 '21 at 21:04
  • @teemu that's why i pointed without freezing / hanging and asked for the time to process that – Ahmed Shahin Dec 14 '21 at 21:19
  • Print to where? Lines in the console are very limited for this task, and I doubt any browser could handle all the 3 billion+ elements needed. To paper..? 800 permutations on a page (A4 double side) makes 3843240 sheets (80g/m² =>19 tons of paper), considering printer lifetime, at least 4 - 5 printers, how much ink, I can't even estimate. 4 secs/page makes roughly 180 days ... And who's going to read that list and why? The question simply is not practical. – Teemu Dec 15 '21 at 06:06
  • @Teemu I think there is misunderstanding , I don't mean to print the result on paper , I meant to print out the result on the html page , like displaying it within the page not on console . I understand the results are going to be huge , I already assumed that computer will freeze out. Thanks for your comments though – Ahmed Shahin Dec 15 '21 at 14:03
  • Well, you really need more efficient tools than JS and a HTML page. I tried to run permute function in [le_m's answer](https://stackoverflow.com/a/37580979/1169519) passing an array length of 11, got Out of memory error after a minute or so. – Teemu Dec 15 '21 at 19:59
  • @Teemu so , on this case maybe there is some tweak to clear the memory when its full to continuo the process. i would love to contact you by email to find more about that if you allow me to. – Ahmed Shahin Dec 15 '21 at 20:41
  • JS has no tools for memory management, the automatic garbage collection takes care of the memory, there's not much you can do. It's notable, that I only ran the function, I didn't try to print the results. – Teemu Dec 16 '21 at 07:17

0 Answers0