Question: Please assist. I am getting this error message below please correct code so that the program can compile successfully. Main.java:7: error: class RecoverPassword is public,

Please assist. I am getting this error message below please correct code so that the program can compile successfully.

Main.java:7: error: class RecoverPassword is public, should be declared in a file named RecoverPassword.java public class RecoverPassword { ^ 1 error

import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;

public class RecoverPassword { /** * * @param source for which ascii equivalent need to be generated * @return ascii equivalent of source */ public String generateASCII(String source){ String charASCII = ""; for (char c:source.toCharArray()){ charASCII += Integer.toString((int)c); } return charASCII; } /** * * @param saltedPassword for which hash value to be generated * @return hash string for corresponding salted password */ public String getHashForPassword(String saltedPassword){ int hash; String hashString; String saltLeft = saltedPassword.substring(0,7); String saltRight = saltedPassword.substring(7,saltedPassword.length());

hash = ((243 * Integer.parseInt(saltLeft)) + Integer.parseInt(saltRight)) % 85767489; hashString = Integer.toString(hash);

return hashString; }

public static void main(String[] args) {

System.out.println("<> Password recovery by ");

if (args.length != 2){ System.out.printf("Invalid number of arguments. Please provide valid number of argumets."); System.out.println("Usage: RecoverPassword "); }

String dictionaryFile = args[0]; String saltedPasswordHashValue = args[1]; String recoveredPass=null, recoveredSalt=null, recoveredPassASCII=null; boolean passFound = false; int index = 1; List candidatePasswords = new ArrayList(); Map passwordToASCII = new HashMap();

System.out.println("\tDictionary file name " + dictionaryFile); System.out.println("\tSalted password hash value " + saltedPasswordHashValue);

/* Read file content*/

try { BufferedReader br = new BufferedReader(new FileReader(new File(dictionaryFile))); String line; while ((line = br.readLine()) != null) { if(line.trim() != "") { candidatePasswords.add(line);

} } } catch (FileNotFoundException e) { System.err.println("Dictionary file not found."); } catch (IOException e) { System.err.println("Problem while reading dictionary file."); }

RecoverPassword recoverPassword = new RecoverPassword(); String salt, hashString, saltedPassword, passASCII; int numberOfCombinations = 0;

/* Print index */

System.out.println("Index Word Unsalted ASCII equivalent"); for(String pass:candidatePasswords){ passASCII = recoverPassword.generateASCII(pass); passwordToASCII.put(pass, passASCII);

System.out.println(" " + Integer.toString(index) + " : " + pass + " " + passwordToASCII.get(pass));

index++; }

/* Recover password */ for(String pass:passwordToASCII.keySet()){ /* Salt password */ passASCII = passwordToASCII.get(pass); for(int i=0; i<=999; i++){ salt = String.format("%03d", i); saltedPassword = salt + passASCII;

hashString = recoverPassword.getHashForPassword(saltedPassword);

numberOfCombinations++;

if(saltedPasswordHashValue.compareTo(hashString)==0){

passFound = true;

recoveredPass = pass; recoveredPassASCII = passASCII; recoveredSalt = salt;

break; } } }

if(passFound){ System.out.println("Password recovered:"); System.out.println("Password recovered : " + recoveredPass); System.out.println("ASCII value : " + recoveredPassASCII); System.out.println("Salt value : " + recoveredSalt); }else { System.out.println("Password not found in dictionary."); }

System.out.println("Combination tested: " + Integer.toString(numberOfCombinations));

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!