Hello,
Before continuing a task that someone suggested for a mini-project, do you believe there is a more accurate way to identify hashes? Currently, I am using regex + length of hash to give the user possible hashes.
Identifier class:
package votek; /*Author: Votek/Karil Votek * Purpose: Class is used to run checks on possible hashes that the user has entered. */ public class Identifier { //Hash entered by user is stored here private String hash; //String that will contain all possible hashes to share with user private String results = "Possible Hashes: "; //Method that runs the other hash methods checks and prints out the results. public void runHashCheck(String hash) { //setting Identifier's private instance 'hash' to the String given by user this.hash = hash; //Methods for each hash checkMD2(); checkMD5(); checkSHA1(); //If the results variable did not change, tells user nothing was found. Otherwise, shares possible hashes. if(results == "Possible Hashes: ") { System.out.println("No possible hashes were found."); } else { System.out.println(results); results = "Possible Hashes: "; } } //Method to check for MD2 hash private void checkMD2() { boolean isMD2 = hash.matches("[0-fA-F0-9]{32}"); if(isMD2) { results += "MD2 "; } } //Method to check for MD5 hash private void checkMD5() { boolean isMD5 = hash.matches("[0-fA-F0-9]{32}"); if(isMD5) { results += "MD5 "; } } //Method to check for SHA1 hash private void checkSHA1() { boolean isSHA1 = hash.matches("[0-fA-F0-9]{40}"); if(isSHA1) { results+= "SHA1 "; } } //More hash check methods will follow }// end of Identifier class
HashIdentifier Class (main):
/*Author: Votek/Karil Votek * Program: User inserts a hash and methods are ran to determine possible hashes the hash may be. */ package votek; import java.util.Scanner; public class HashIdentifier { public static void main(String[] args) { //Creating & initializing an object for the Identifier class & Scanner class Identifier identifier = new Identifier(); Scanner user = new Scanner(System.in); //Used to stop the loop char quit = 'n'; //Continue loop of user inputting hashes/checking hashes while(Character.toLowerCase(quit) != 'q') { System.out.print("Please enter the hash you would like to check: "); identifier.runHashCheck(user.nextLine()); System.out.println("Enter 'q' if you would like to quit the program. Otherwise, enter any other character: "); quit = user.nextLine().charAt(0); } user.close(); } } //end of HashIdentifier class