Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please modify the code below to meet all the requirements also shown below. I have a protected5.zip file along with the zip4j library shown below.

please modify the code below to meet all the requirements also shown below. I have a protected5.zip file along with the zip4j library shown below.

import java.util.Calendar;

import net.lingala.zip4j.core.*;

import net.lingala.zip4j.exception.*;

public class PasswordCracker {

public static void main(String[] args) {

long startTime = System.currentTimeMillis(); // get the start time

char[] pwd = new char[3]; // char array to hold the password

crackPassword(pwd, 0); // call the recursive function

long endTime = System.currentTimeMillis(); // get the end time

System.out.println("Password cracked in " + (endTime - startTime) + "ms");

}

// This is a recursive function that finds the correct password.

public static void crackPassword(char[] pwd, int index) {

for (char c = 'a'; c

pwd[index] = c; // set the current index to the current letter

if (index == pwd.length-1) { // if we have reached the end of the array

String password = new String(pwd); // get the String representation of the array

try {

ZipFile zipFile = new ZipFile("protected5.zip");

zipFile.setPassword(password);

zipFile.extractAll("contents");

System.out.println("Password found: " + password);

return; // exit the function

} catch (ZipException ze) {

// do nothing, this just means the password was incorrect

} catch (Exception e) {

e.printStackTrace();

}

} else { // if we have not reached the end of the array

crackPassword(pwd, index + 1); // recursively call the function

}

}

}

}

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
You have also been provided with another file, called protected5 . zip. As the name implies, this file is protected by a five-character password, still only made of lowercase letters. Because this password has more characters, your approach from Part 1 will take a long time to finish. Therefore, for this step you need to multithread your original implementation. This is required - you will not receive credit for programs that break this password using only a single thread. Your program must include a variable called numThreads that contains a hard-coded integer value to control the number of child threads spawned to look for the password. You can tweak this setting to your liking while testing your program - just make sure it is named as requested so that we can easily do the same. The multi-threaded version of your program should still quit as soon as any of the threads finds the password. To accomplish this, you will need a way to enable the main thread to detect when any of its child threads successfully finds the password and, if/when that happens, terminate the remaining child threads and quit. This is a great place to use a volatile static variable. When timing the amount of time the program takes, include both the time to generate the passwords and the time for the threads to run. Run your program with three and then with four threads and put the number of milliseconds it took to get the password as a comment at the top of your driver class (i.e. the one with main in it).Important: Because all of your threads will be trying to decrypt the file, if they were to all use the same file, that would create a bottleneck. To avoid this, each of your threads needs to make its own copy of the file to work on. Also, the method extractAll () , in addition to testing the password you set using set Password ( ) , leaves behind a directory (called contents in the starter code) that contains the results of its attempt at decrypting the . zip file. Since now all of the child threads will be using the extractAll ( ) method, you'll need a way to specify a different place for each one to write its results to by changing 'contents" to something unique for each thread like "contents-0", "contents-1", etc. Your threads should delete their copy of the target file and their contents directory when they finish. To receive full credit, this must all be done programmatically - you cannot manually make copies of the protected file before your program runs. As a reminder, here is some code that copies / deletes files: import java . nio. file. Files; import java . nio. file. Path; Files . copy (Path. of (srcFilename) , Path. of (destinationFilename) ) ; Files . delete (Path . of (filename) ) ; Keep in mind that to delete a directory, you must first delete any files inside it. Examples > java -cp . :zip4j-1.3.2. jar ZipCrackerSingleThread Password is Finished in 1913 ms'S( C] Name V Today 3E protected5 : contents V Yesterday 3 Example 3E protected3 D Example.class m zip4j1.3.2 j PasswordCracker j PasswordCracker.class Date modified 4/15/2023 12:38 PM 4/15/2023 1:38 AM 4/14/2023 10:30 PM 4/14/2023 10:22 PM 4/14/2023 2:34 PIV 4/14/20231:51 PIV 4/14/2023 1:40 PIV 4/14/2023 12:05 AM Type Compressed (zipped)... File folder Java Source File CLASS File Java Source File Compressed {zipped}... CLASS File JAR File PS C: \\Users\\zayda\\downloads \\hello> java -cp ./zip4j-1.3.2. jar Protected5Cracked . java Exception in thread "main" java. io. FileNotFoundException: dictionary. txt (The system cannot find the file specified) at java. base/java. io. FileInputStream. open0(Native Method) at java. base/java. io. FileInputStream. open(FileInputStream. java: 216) at java. base/java. io. FileInputStream. (FileInputStream. java: 157) at java. base/java. io. FileInputStream. (FileInputStream. java: 111) at java. base/java. io. FileReader. (FileReader . java: 60) at Protected5Cracked . readDictionaryFile(Protected5Cracked . java : 45) at Protected5Cracked . main (Protected5Cracked . java : 25) PS C: \\Users\\zayda\\downloads \\hello> / 11 Col 31 Spaces: 4 UTF-8loday Protected5Cracked$CrackPasswordThread.cl... 4/15/2023 7:46 PM CLASS File Protected5Cracked.class 4/15/2023 7:46 PM CLASS File Protected5Cracked 4/15/2023 7:44 PM Java Source File PasswordCracker.class 4/15/2023 5:28 PM CLASS File PasswordCracker 4/15/2023 5:02 PM Java Source File protected5 4/15/2023 12:38 PM Compressed (zipped).. contents 4/15/2023 5:02 PM File folder Yesterday Example 4/14/2023 2:34 PM Java Source File

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

Which of the following situations describes a representation?

Answered: 1 week ago