# Password Cracking with Brute Force Algorithm and Dictionary Attack Using Parallel Programming
## 4 Empirical Studies
### Experimental Setup
#### 4.2.2 Dictionary Attack Setup  
The dictionary attack consists of different experiments. The first one was implemented with Python to compare it with brute force (first experiment). The second one was performed with the use of OpenMP to see the different performances acquired when changing the parameters of the clauses. For the first experiment, we used Python to set up a parallelized password-cracking experiment. The experiment uses the Python standard library's \"multiprocessing\" module to create and manage child processes. The child processes the \"password_check\" function parallelly, each checking a portion of a dictionary of possible passwords to find a match with the target password. The main program, defined in the \"main\" function, starts by reading a target password from the user and then loads a dictionary of possible passwords from a file we named \"dictionary.txt\". The dictionary is split into \"num_processes\" equal parts (8 parts in this case, and it can be changed), and \"num_processes\" child processes are started to parallelly check each part of the dictionary. Each child process is passed the dictionary, the target password, and the indices marking the start and end of the portion of the dictionary it should check as arguments to the \"password_check\" function. If a password match is found, the \"password_check\" function outputs information about the matching password and the elapsed time, then returns. After starting the child processes, the main program waits for all child processes to finish by calling join on each. The code uses the \"time\" module to measure the elapsed time of password checking. These are the parameters that were used:  
* \"dictionary\": a list of strings representing a dictionary of possible passwords. * \"target\": a string representing the target password to be found. * \"start_index\": an integer representing the starting index of the portion of the dictionary to be checked by a child process. * \"end_index\": an integer representing the ending index of the portion of the dictionary to be checked by a child process. * \"num_processes\": an integer representing the number of child processes to be created and used for parallelizing password checking. * \"chunk_size\": an integer representing the size of each chunk of the dictionary, calculated as the length of the dictionary divided by \"num_processes\". * \"processes\": a list to store the created child processes. * \"file\": a file object representing the \"dictionary.txt\" file. * \"passwd\": a string representing a password from the \"dictionary.txt\" file, read one at a time in a loop. * \"p\": a process object representing a child process. For the second experiment, we wrote a code that functions similarly to the Python code. However, the purpose here is to compare different settings of using OpenMP, such as the number of cores and the type of schedule. The program reads a list of potential passwords from a file named \"dictionary.txt\" (RockYou passwords) and stores it in a vector called \"dictionary\". The user is prompted to enter the target password, which is stored in the variable \"target\". The program then uses the \"#pragma omp parallel for\" directive to parallelize a for-loop that iterates through the elements of the \"dictionary\" vector and compares each one to the target password. The \"num_threads\" clause sets the number of threads to any number you wish to test depending on your machine, and the \"schedule(Typeofschedule, NumberOfChuncks)\" sets the scheduling method for distributing iterations among the threads to be the type of schedule you are willing to test (static or dynamic) with a chunk size that you can set. If a match is found, the program outputs the matching password and the number of the iteration in the for-loop that found the match, as well as the number of threads that found the match and the total number of passwords in the dictionary. Finally, the program measures and outputs the elapsed time in milliseconds using the \"chrono\" library.