Results 1 to 8 of 8

Thread: Hash

  1. #1
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Hash

    Hello everyone,

    Today I have made a hash identifier based on some sort of information. Have a look at this link :- Cryptography : Identify Hash types

    I have made the thread above and now I am making a hash identifier. I have came up with something and here's the code.

    HashIdentifier.java (It has the main class)
    Java Code:
    package hashidentifier;
    
    import java.util.Scanner;
    
    public class HashIdentifier {
    
        private static final String NEWLINE = System.getProperty("line.separator");
        private static final String PROJECT_TITLE = "   __ __         __     ____   __         __  _ ____"
                + NEWLINE + "  / // /__ ____ / /    /  _/__/ /__ ___  / /_(_) _(_)__ ____   "
                + NEWLINE + " / _  / _ `(_-</ _ \\  _/ // _  / -_) _ \\/ __/ / _/ / -_) __/"
                + NEWLINE + "/_//_/\\_,_/___/_//_/ /___/\\_,_/\\__/_//_/\\__/_/_//_/\\__/_/              By Psycho_Coder at"
                + NEWLINE;
        private static final String HC_TITLE = ""
                + "_  _ ____ ____ _  _ ____ ____ _  _ _  _ _  _ _  _ _ ___ _   _  ____ ____ _  _"
                + NEWLINE
                + "|__| |__| |    |_/  |    |  | |\\/| |\\/| |  | |\\ | |  |   \\_/   |    |  | |\\/|"
                + NEWLINE
                + "|  | |  | |___ | \\_ |___ |__| |  | |  | |__| | \\| |  |    |   .|___ |__| |  |"
                + NEWLINE;
    
        public static void main(String[] args) {
            boolean hashFound = false;
            HashDetected obj = new HashDetected();
            Scanner sc = new Scanner(System.in);
            System.out.println(PROJECT_TITLE);
            System.out.println(HC_TITLE);
            System.out.print("\n\nEnter the hash :- ");
            String hash = sc.nextLine();
            System.out.println("\nLogs :- ");
            System.out.println("\nBeginning Test for MD5 ...... ");
            while (!hashFound) {
                MD5Test ob = new MD5Test();
                if (ob.MD5(hash)) {
                    hashFound = true;
                    System.out.println("MD5 Hash Detected");
                    System.out.println("\nType of Hash found : "+obj.lst.get(0).toString());
                }
            }
        }
    }
    MD5Test.java

    Java Code:
    package hashidentifier;
    
    public class MD5Test {
    
        public boolean MD5(String hash) {
            HashDetected ob = new HashDetected();
            boolean hashFound = false;
            int length = hash.length();
            if (length == 32) {
                ob.addToList("MD5");
                hashFound = true;
            }
            if (length == 34) {
                if (hash.startsWith("$1$")) {
                    ob.addToList("MD5(UNIX)");
                    hashFound = true;
                } else if (hash.startsWith("$P$")) {
                    ob.addToList("MD5(Wordpress)");
                    hashFound = true;
                } else if (hash.startsWith("$H$")) {
                    ob.addToList("MD5(phpBB3)");
                    hashFound = true;
                }
            }
            if (length == 37) {
                if (hash.startsWith("$apr1$")) {
                    ob.addToList("MD5(APR)");
                    hashFound = true;
                }
            }
            return hashFound;
        }
    }
    HashDetected.java

    Java Code:
    package hashidentifier;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class HashDetected {
    
        public static List<String> lst = new ArrayList<String>();
    
        public void addToList(String a) {
            lst.add(a);
        }
    }
    The above will identify : MD5, MD5(UNIX), MD5(APR), MD5(phpBB3) and MD5(Wordpress). I can make it for all the other tyoes of hashes. But that would make my code left with a large built of if-else construct. But I want something more optimized and better and that is flexible.

    My new plan of doing this :- Make a file with the hash characteristics and store them and the identifying characteristics there and then check the hash given by the user against the stored data in the file. I think in this way my code will be more optimized.


    Well but my question is what manner should I store the data in the file. How do I organise it. Any hints along with some codes (I am not proficient in file handling)

    Thank you,
    Sincerely,
    Psycho_Coder

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,739
    Rep Power
    7

    Default Re: Hash

    Why not a simple text file with some sort of delimiter. I believe there is a precedent for that in the magic numbers file associated with Unix machines to identify types of files.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: Hash

    Quote Originally Posted by jim829 View Post
    Why not a simple text file with some sort of delimiter. I believe there is a precedent for that in the magic numbers file associated with Unix machines to identify types of files.

    Regards,
    Jim
    Will you please make your self clear. I didn't understood quite well what you wanted to convey

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default Re: Hash

    A minor nitpick: I don't know who told you that nonsense about that NEWLINE hoopla, but the print( ... ) and println( ... ) methods alread convert a single \n character to the system dependent character sequence. It are the write( ... ) methods that print the character as is.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,739
    Rep Power
    7

    Default Re: Hash

    Example (assuming I understand what you are looking for) -- # denotes comments

    # prefix:hash method:length
    $1$:MD5(UNIX):34
    $P$:MD5(WordPress):34
    $APR$1:MD5(APR):37

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    CodeX Pro is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: Hash

    Quote Originally Posted by JosAH View Post
    A minor nitpick: I don't know who told you that nonsense about that NEWLINE hoopla, but the print( ... ) and println( ... ) methods alread convert a single \n character to the system dependent character sequence. It are the write( ... ) methods that print the character as is.

    kind regards,

    Jos
    Well I don't find anything wrong with that implementation

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,051
    Blog Entries
    7
    Rep Power
    23

    Default Re: Hash

    Quote Originally Posted by CodeX Pro View Post
    Well I don't find anything wrong with that implementation
    Well, daemons won't fly out of your nose, nor will any other world wide disaster happen, but print()ing \r\n (that's what the end-of-line sequence is on an MS Windows machine) makes it print \r\r\n on it because of the translation of \n itself.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  8. #8
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,739
    Rep Power
    7

    Default Re: Hash

    The proper response would be "Oh, OK, I didn't realize that. Thanks!"

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Replies: 9
    Last Post: 11-12-2012, 12:38 PM
  2. Hash set
    By lakshmibvaraprasad in forum New To Java
    Replies: 2
    Last Post: 07-20-2011, 06:58 PM
  3. Hash-tables IO
    By loopsnhoops in forum New To Java
    Replies: 8
    Last Post: 06-01-2011, 09:55 AM
  4. Hash
    By sandy1028 in forum New To Java
    Replies: 4
    Last Post: 04-17-2009, 10:36 AM
  5. Hash Map
    By rekha in forum New To Java
    Replies: 1
    Last Post: 03-21-2009, 02:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •